string to integer

28 views
Skip to first unread message

mohitnegi

unread,
Oct 11, 2011, 1:58:44 AM10/11/11
to thinkin...@googlegroups.com
I am storing my date field as a string format in my database i.e. "Jun2011",

Now is there a way that while filtering sphinx search i can have integer search.

like i want to search for all data with year less than 2011,  how can i do that

Something like  Model.search :with{:start_year.<something>=>0..2011}

Pat Allan

unread,
Oct 11, 2011, 2:06:40 AM10/11/11
to thinkin...@googlegroups.com
You'll need to extract the year into an attribute using a bit of SQL:

has "substring(date_column, 3, 4)", :as => :start_year, :type => :integer

No idea whether substring exists in MySQL or PostgreSQL, so consider the above as a pseudo-code example. Filtering though is like so:

Model.search :with => {:start_year => 0..2010}

This doesn't take months into account, though, but you get the idea :)

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/vNULtbWWiGcJ.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.

mohitnegi

unread,
Oct 11, 2011, 3:02:52 AM10/11/11
to thinkin...@googlegroups.com
Thanks a lot Pat, I got it :)
Reply all
Reply to author
Forward
0 new messages