简体   繁体   中英

Thinking Sphinx Combining :with parameters

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM