本文介绍了Where 子句在 Sphinx 中有 OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 sphinx 搜索中做这行

Is there a way to do this line in sphinx search

where field_a = 'Value' or field_b = 'Value'

到目前为止我已经尝试过

I have tried so far

$sphinx->where(field_A | field_B, '=', 'Value')

但它不起作用.有人能帮我解决这个问题吗?

But it's not working.Could someone help me to get over this?

推荐答案

Sphinx 本身不支持 WHERE 子句中的OR".

Sphinx itself does not support 'OR' in the WHERE clause.

但可以做类似的事情

SELECT id, (attribute_a = 'Value' OR attribute_b = 'Value') AS test
FROM index
WHERE test = 1

有点复杂,但确实有效.也不知道您使用什么库来构建查询,因此将如何构建像上面这样的 SQL 查询作为练习.

It's a little convoluted, but does work. Also no idea what library you using to build the query, so left as an exercise to how to construct a SQL query like above.

(另请注意,我改为将列称为属性.Sphinx 对属性和字段的处理方式非常不同.澄清这是过滤属性的一种方式)

(Also note I changed to call the column, attributes instead. Sphinx treats attributes and fields very differently. Clarifying this is a way of filtering attributes)

这篇关于Where 子句在 Sphinx 中有 OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:44