Conditional search based on boolean field.

16 views
Skip to first unread message

Kushagra

unread,
Feb 26, 2015, 10:39:15 AM2/26/15
to ruby-s...@googlegroups.com
Hey ,

I've been stuck with this for quite a while now , so any help would be greatly appreciated . 

The issue is : 

1.There is a is_catalogue:boolean field for a product .
2. We want Solr to return products whose price is equal to and greater than 0 when is_catalogue is true for a product.
3. We want Solr to return products whose price is only greater than 0 and NOT equal to 0 when is_catalogue is false for a product.
4.This needs to be done in the same query to solr.

<pre>
   Product.solr_search do
        fulltext keywords unless keywords.blank?
        with :taxon_ids, [taxon] unless taxon.blank?
        with :product_type_taxons, product_types unless product_types.blank?

        if price_range
          with(:price).between(price_range)
        else
          with(:is_catalogue, true) do
            with(:price).greater_than_or_equal_to(0)
          end
          with(:is_catalogue, false) do
            with(:price).greater_than(0)
          end  
        end
      end
</pre>
I tried the above code but that does not seem to work .
Is there any way to achieve this using Sunspot::Solr


Reply all
Reply to author
Forward
0 new messages