(思考)sphinx Extended2模式下如何进行属性匹配?
我有这个表达式,它在 Thinking Sphinx 中按预期工作:
Customer.search :with => {:signer_id => 23}
但我需要编写一个带有某些属性的 OR 的表达式,例如 Signer_id 是 23 或 admin_level 是 42,所以我转到扩展匹配模式并写了这个
Customer.search "@signer_id 23", :match_mode => :extended2
:理解Sphinx相关文档,应该是等价的,但是它根本不匹配任何东西。有什么想法我做错了什么吗?如何编写扩展思维的狮身人面像表达式?
从控制台复制并粘贴:
ruby-1.8.7-p302 > Customer.search(:with => {:signer_id => 23}).count
=> 20
ruby-1.8.7-p302 > Customer.search "@signer_id 23", :match_mode => :extended2
=> []
ruby-1.8.7-p302 > Customer.search("@signer_id 23", :match_mode => :extended2).count
=> 0
更新:修复了 ID (32 -> 23)。
I have this expression which is working as expected in Thinking Sphinx:
Customer.search :with => {:signer_id => 23}
but I need to write an expression with OR of some attributes, like signer_id is 23 or admin_level is 42, so I moved to extended match mode and wrote this:
Customer.search "@signer_id 23", :match_mode => :extended2
which according to my understanding of the Sphinx relevant documentation, it should be equivalent, but it doesn't match anything at all. Any ideas what am I doing wrong? How do I write an extended thinking sphinx expression?
Copied and pasted from the console:
ruby-1.8.7-p302 > Customer.search(:with => {:signer_id => 23}).count
=> 20
ruby-1.8.7-p302 > Customer.search "@signer_id 23", :match_mode => :extended2
=> []
ruby-1.8.7-p302 > Customer.search("@signer_id 23", :match_mode => :extended2).count
=> 0
Update: fixed the id (32 -> 23).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有在文档中发现可以使用
@attribute value
语法的部分 - 它仅适用于字段,不适用于属性。至少,这是我的理解。如果我错了那就太好了:)I'm not spotting the section in the docs that says you can use the
@attribute value
syntax - it's only for fields, not attributes. At least, that's my understanding. Would be fantastic if I'm wrong :)我这样做是为了对我已经标准化的字段进行匹配。通过在全文搜索中使用相同的文本,可以减少数据库中的流失量。
查询:'披萨| @产品代码(965|1636|1848|2939|4227|5067|5735)| @品牌代码 (1485) | @service_codes (2782)
请注意,正如其他答案指出的那样,您不能以这种方式处理属性,这些属性必须是索引字段。
我像这样暴力破解它们:
另外,您需要通过设置此选项来减少单词中的字符数
,否则它将与您的 1 和 2 位数字代码不匹配。
I did this to do matching on fields that I have normalized out. This reduces the amount of churn in the db by having the same text in the full text search.
Querying: 'pizza | @product_codes (965|1636|1848|2939|4227|5067|5735) | @brand_codes (1485) | @service_codes (2782)
Note as the other answer points out you cannot do properties this way, these have to be indexed fields.
I brute force them out like this:
Additionally you will need to reduce the number of characters in a word by setting this
Otherwise it won't match your 1 and 2 digit number codes.