I'm new to Sphinx and am trying to get it configured correctly. I want to allow partial word matching for all searches and do not want users to have to type in wildcard characters on their own.
I'm wanting the search to function like on Amazon or Google where if you start typing a word, suggestions will come up. So, for example, if someone typed in "x", then matches like "Xbox" should appear.
Here are the index settings I currently have:
min_word_len = 1
min_prefix_len = 1
prefix_fields = name
charset_type = utf-8
On the PHP side of things, I'm using SPH_MATCH_EXTENDED2
and SPH_SORT_RELEVANCE
. I left the ranking mode to the default, whatever that is. These settings seemed to provide the best search results when I changed the settings based on trial and error.
I've read similar questions on here and on other sites, but the answers always seem to reference enable_star
which the documentation says is deprecated.
So my question is, how do I enable partial word matches in Sphinx? Should I simply append *
to every word in a users query, doing something like this?
$search = str_replace(' ', '* ', trim($search)) + '*';
You can set expand_keywords = 1
as described in the docs.
It actually pretty much just adds the stars for you automatically - in a way that in general the exact matches will rank slightly higher than pure 'part' matches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With