Ah, if an integer's what you need, then what you've suggested is pretty much 
spot on - you just don't need :sortable => true :)

-- 
Pat

On 20/08/2010, at 12:20 AM, Jon wrote:

> Thanks so much for that Pat, been scratching my head the last couple of hours 
> (and i do have other attributes in there too!)
> 
> FWIW, i think you cast as an unsigned in Mysql
> 
> has "cast(price as unsigned)", :type=>:integer, :as=> :sphinx_price, 
> :sortable=>true
> 
> cheers
> 
> jon
> 
> 
> On Thu, Aug 19, 2010 at 11:30 PM, Pat Allan <[email protected]> wrote:
> Hi Jon
> 
> There's a couple of things to keep in mind that should get you on the way to 
> what you want:
> * :with is for attributes (not fields) - and you definitely want an attribute 
> when dealing with numbers.
> * If your attribute is a float (which is what decimals get converted to), 
> you'll need to filter by floats.
> 
> So, change that 'indexes' line to a 'has' line (and remember - attributes are 
> sortable by Sphinx without any trickery):
> 
>  has price
> 
> And then for filtering:
> 
>  Event.search '*a*', :with => {:price => 1.0..1000.0}
> 
> You could try aiming for exact values, but not sure how reliable that is with 
> floating point values...
> 
>  Event.search '*a*', :with => {:price => 11.0}
> 
> If that doesn't work, try the following:
> 
>  Event.search '*a*', :with => {:price => 10.59..11.01}
> 
> One last unrelated thing: if you always want stars around each word, just use 
> :star => true when searching :)
> 
> Hope this helps.
> 
> --
> Pat
> 
> On 19/08/2010, at 11:49 PM, Jon wrote:
> 
> > Hi
> >
> > I'm trying to index a decimal(8,2) field in MySQL.
> >
> > I'm trying to do it like this in the model:
> > define_index do
> >   indexes "cast(price as unsigned)", :as=> :sphinx_price, :sortable=>true
> > end
> >
> > I rebuild the index and try to search, but nothing seems to work:
> > e=Event.search :with=>{:sphinx_price=>11}
> > e=Event.search "*a*" :with=>{:sphinx_price=>11}
> >
> > I really want it to find a range, but this doesn't work either:
> > e=Event.search "*a*" :with=>{:sphinx_price=>1..1000}
> >
> > They just return empty set, if i do a:
> > e=Event.search "*a*"
> > I get all the results I expect to.....
> >
> >
> > Any help would be much appreciated :)
> >
> > Thanks
> >
> > Jon
> >
> >
> >
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Thinking Sphinx" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group at 
> > http://groups.google.com/group/thinking-sphinx?hl=en.
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to