Hey Pat,
Thanks for getting back to me, apologies for the delay - been sick :(
I had written a message earlier with some theoretical options, but
decided to dive straight in. What I'm experiencing is a strange
behaviour.
My code is:
  def self.search_for(params)    options =
Product.build_options_from(params)    price =
Product.price(params[:price])    Product.search params[:search], 
  :with => { :price => price },    :order => "@relevance DESC", 
  :rank_mode => :bm25,    :page => params[:page],      :per_page =>
42,     :field_weights => {      :name         => 10,   
  :description  => 7,      :brand        => 3,      :store        =>
3}  end
and my TEST price code like this:
  def self.price(price)    if price == 1      return (0..2000)   
elsif price == 2      return (2000..4000)    elsif price == 3     
return (4000..6000)    elsif price.empty? || price.nil? ||
price.blank?      return (0..100000000)    end  end
Now. The behaviour. When I hard code ONE range into this so self.price
(0..2000) it works. Shows me products <£20. If I change the last elsif
to just else (0..10000000000) (to accomodate everything) - again, it
sort of works - it returns the else for everything, ignoring my
conditions. So then I try and hard-code the "well ok, if its there but
blank/nil/empty THEN return the big range" - it breaks it.
Do you have any idea why this might be happening? I appreciate I
perhaps am not doing it the 'thinking-sphinx' way, maybe?
Thanks in advance. I feel like I'm very close to having what I need!
Cheers,
Geoff
On Nov 29, 11:17 am, Pat Allan <[email protected]> wrote:
> Hi Geoff
>
> Two thoughts thus far: store is a field, not an attribute, so that means you 
> can't filter by it (the :with option). Also - is price an integer, or a 
> float/decimal? If the latter, then ranges must be of the same datatype, so 
> 10.0..100.0 in your example.
>
> Is there a reason for store being a field instead of an attribute?
>
> --
> Pat
>
> On 28/11/2011, at 6:11 PM, Geoff Wright wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I discovered :with last night, being that we run an online store I've
> > been looking for a while on how to send an array through to Sphinx to
> > return results for a GROUP of say, Brands. Or even, using ranges for
> > prices - however, I just can't seem to get it to work!
>
> >  # Sphinx index configuration
> >  define_index do
> >    indexes name, :sortable => true
> >    indexes description
> >    indexes brand, :facet => true
> >    indexes feed_id, :as => :store, :facet => true
> >    has :price
> >    has :created_at
> >  end
>
> > ^ This is my current configuration
>
> > @products = Product.search 'dress', :with => {:store => [14,15]}
>
> > ^ With the configuration in mind, when I run the above I get :
>
> >>> @products = Product.search 'dress', :with => {:store => [14,15]}
> > ThinkingSphinx::SphinxError: index product_core: no such filter
> > attribute 'store'
>
> > When I try to use Price Ranges, I get:
>
> >>> @products = Product.search 'dress', :with => {:price => 10..100}
> > ThinkingSphinx::SphinxError: index product_core: no such filter
> > attribute 'price'
>
> > I get the feeling that something in my approach is wrong. Can anyone
> > point me in the right direction?
>
> > Thanks in advance
>
> > Geoff
>
> > --
> > 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 
> > athttp://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