Conditional search based on boolean value

23 views
Skip to first unread message

kusha...@treniq.com

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

I've been facing an issue and have not been able to come up with a solution so far so any sort of help is greatly appreciated . 

The Issue is I want to be able to search for product.

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>
    Spree::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
          # tried doing it like this , but did not have much luck
          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>

Thanks 
Reply all
Reply to author
Forward
0 new messages