Reputation: 7065
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.
Upvotes: 0
Views: 518
Reputation: 21091
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)
Upvotes: 1
Reputation: 4385
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
Upvotes: 0