views:

19

answers:

1

Hi guys,

I was wondering how I could combine the result sets of Thinking Sphinx

I have the following query:

Model.search :with => {:attribute_1 => id}

Which I want to combine with:

Model.search :with => {:attribute_2 => id}

Is there a neat way to do this with just one search? I could do array addition but that does no seem to be a good solution at all. If I combine the filters like this:

Model.search :with => {:attribute_1 => id, :attribute_2 => id}

the results are the intersection of the two filters, which is not the desired output. Is there any way to do an OR operation with the filters.

A: 

This really comes down to a limitation in Sphinx - which has no concept of ORs when referencing attributes in filters.

Perhaps you could combine the two attributes together? Then the following would work:

Model.search :with => {:attr_1_and_2 => id}

In your model, if you're dealing with single values, this will definitely work - and maybe with arrays of values:

has [attribute_1, attribute2], :as => :attr_1_and_2
pat
I think this is exactly what I am looking for. Thanks for the tip!
Lester Celestial