简体   繁体   中英

Sphinx - Search phrase in comma separated string

In Sphinx , I want to search for a phrase in comma separated string.

For example, the comma separated string is Very Expensive,Luxury,Romance,Trendy .

The phrase "Expensive" should not match this record, but the phrase "Very Expensive" should be matched.

Tried setting Phrase Boundary option in sphinx configuration file and rotated the indexer again, but there is no change in the output.

phrase_boundary                 =  U+002C # comma
phrase_boundary_step            =  100

I'm using Sphinx 2.0.5 with PHP as scripting language.

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 :)


(can build this dynamically in sql_query , eg

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

(at least for a mysql data source)

You could make use of the field-start and field-end modifiers using the Extended query syntax . 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

^Expensive$ - does not match the entire field

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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