Thinking sphinx string date attribute -
i have column 'value' of type text. can contain regular text, , dates in string format. index column indexes value
. can add attribute converts column integer? tried both of following:
has "str_to_date(model.value, '%y-%m-%d')", as: :value_as_date, type: :integer has "convert(model.value, datetime)", as: :value_as_date, type: :integer
thanks
there's 2 approaches here... sphinx has timestamp (datetime) data type attributes, use that:
has "convert(model.value, datetime)", as: :value_as_date, type: :timestamp
or, may better use integer representing date (because sounds don't ned time aspect) extracting date string, , converting %y%m%d value integer (note, no hyphens in date format).
has "... more complex sql snippet ...", as: :value_as_date, type: :integer
in situation, you'd need convert dates filters integers of same format well.
all of aside: you'll want have in sql snippets handles situations value
column holds other date. or perhaps it's worth pulling date values out separate column have more consistent data? (easy suggest without knowing full context of app, know.)
Comments
Post a Comment