开发者

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开发者_如何学Python 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜