如何在(思考)sphinx extended2模式中进行属性匹配?

时间:2010-09-17 15:23:30

标签: ruby sphinx thinking-sphinx

我的这个表达式在Thinking Sphinx中正常运作:

Customer.search :with => {:signer_id => 23}

但是我需要用一些属性的OR写一个表达式,比如signer_id是23或者admin_level是42,所以我转到扩展匹配模式并写了这个:

Customer.search "@signer_id 23", :match_mode => :extended2

根据我对Sphinx relevant documentation的理解,它应该是等价的,但它根本不匹配。有什么想法我做错了什么?我如何写一个扩展思维的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)。

2 个答案:

答案 0 :(得分:0)

我这样做是为了对我已经规范化的字段进行匹配。通过在全文搜索中使用相同的文本,这可以减少数据库中的流失量。

查询:'披萨| @product_codes(965 | 1636 | 1848 | 2939 | 4227 | 5067 | 5735)| @brand_codes(1485)| @service_codes(2782)

注意,另一个答案指出你不能这样做属性,这些必须是索引字段。

我粗暴地强迫他们这样:

        indexes '(select group_concat(products.id) from business_products inner join products on (products.id = business_products.product_id) where business_id = `businesses`.`id` group by business_id)', :as => :product_codes, :type => :integer

此外,您需要通过设置此

来减少单词中的字符数
  min_word_len: 1

否则它将与您的1位和2位数字代码不匹配。

答案 1 :(得分:0)

我没有发现文档中可以使用@attribute value语法的部分 - 它仅适用于字段,而不适用于属性。至少,这是我的理解。如果我错了会很棒:)