思考Sphinx组合:与参数

发布于 2024-09-24 09:50:14 字数 461 浏览 3 评论 0原文

我想知道如何组合 Thinking Sphinx 的结果集

我有以下查询:

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

我想与之组合:

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

有没有一种巧妙的方法只需一次搜索即可做到这一点?我可以进行数组加法,但这似乎根本不是一个好的解决方案。如果我像这样组合过滤器:

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

结果是两个过滤器的交集,这不是所需的输出。有没有办法对过滤器进行“或”运算。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2024-10-01 09:50:14

这实际上归结为 Sphinx 的限制——在过滤器中引用属性时,它没有 OR 的概念。

也许你可以将这两个属性结合在一起?那么以下内容将起作用:

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

在您的模型中,如果您正在处理单个值,这肯定会起作用 - 也许也适用于值数组:

has [attribute_1, attribute2], :as => :attr_1_and_2

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文