简体   繁体   English

Sphinx-用逗号分隔的字符串搜索短语

[英]Sphinx - Search phrase in comma separated string

In Sphinx , I want to search for a phrase in comma separated string. Sphinx ,我想用逗号分隔的字符串搜索短语。

For example, the comma separated string is Very Expensive,Luxury,Romance,Trendy . 例如,用逗号分隔的字符串是Very Expensive,Luxury,Romance,Trendy

The phrase "Expensive" should not match this record, but the phrase "Very Expensive" should be matched. 短语"Expensive"不匹配此记录,但短语"Very Expensive"应匹配。

Tried setting Phrase Boundary option in sphinx configuration file and rotated the indexer again, but there is no change in the output. 尝试在sphinx配置文件中设置“ 短语边界”选项,并再次旋转索引器,但是输出没有变化。

phrase_boundary                 =  U+002C # comma
phrase_boundary_step            =  100

I'm using Sphinx 2.0.5 with PHP as scripting language. 我将Sphinx 2.0.5PHP用作脚本语言。

How I solve this, (indexing Tags) is to use a specific seperator. 我如何解决这个问题,(为标签建立索引)是使用特定的分隔符。 Eg index it as 例如,将其索引为

_SEP_ Very Expensive _SEP_ Luxury _SEP_ Romance _SEP_ Trendy _SEP_ 

Now can run a query "_SEP_ Very Expensive _SEP_" (with the quotes) and it will match nice, however a query "_SEP_ Expensive _SEP_" will NOT match :) 现在可以运行查询"_SEP_ Very Expensive _SEP_" (带引号),它将很好地匹配,但是查询"_SEP_ Expensive _SEP_"将不匹配:)


(can build this dynamically in sql_query , eg (可以在sql_query动态构建它,例如

... , CONCAT('_SEP_ ',REPLACE(labels,',',' _SEP_ '),' _SEP_') AS labels, ...

(at least for a mysql data source) (至少对于mysql数据源而言)

You could make use of the field-start and field-end modifiers using the Extended query syntax . 您可以使用扩展查询语法来使用field-startfield-end修饰符。 In this case you would need to break your comma separated strings ("Very Expensive", "Luxury" etc) into the separate fields while indexing. 在这种情况下,您需要在索引时将用逗号分隔的字符串(“非常昂贵”,“豪华”等)分成单独的字段。

Your search queries then would look like these: 您的搜索查询将如下所示:

^Very Expensive$ - matches the entire field ^Very Expensive$ -匹配整个字段

^Expensive$ - does not match the entire field ^Expensive$ -与整个栏位不符

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

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