简体   繁体   English

思维狮身人面像结合:带参数

[英]Thinking Sphinx Combining :with parameters

I was wondering how I could combine the result sets of Thinking Sphinx 我想知道如何合并Think 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. 这实际上归结为Sphinx的局限性-当在过滤器中引用属性时,它没有OR的概念。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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