Search code examples
node.jsdatabasepostgresqlfull-text-searchsphinx

Configure sphinx to rank exact matching higher with morphology enabled


I'm having sphinx index to search users by names.

I'm using soundex morphology to show more relevant results for case searcher doesn't exactly know how the name spells. Consider following table:

+----+--------------------+
| id |        name        |
+----+--------------------+
|  1 | Maciej Makuszewski |
|  2 | Dane Massey        |
|  3 | Lionel Messi       |
|  4 | Mr. No Matches     |
+----+--------------------+

With soundex enabled sphinx suggests 1, 2, 3 rows as a relevant result for query messi. Anyway I'd like to show the exact matching first. I mean that if user types messi he wants to see Lionel Messi the first with great probability.

My problem is I don't know how to do that. I tried to set different rankers but it gives nothing.

I also tried to add

index_exact_words = 1

to index but it gives nothing.

I'm using sphinx API with node.js sphinxapi module if it matters.

What is the common way of solving such issue?


Solution

  • You want, index_exact_words, but should also add expand_keywords

    This will cause sphinx to search for the fuzzy (via morphology) AND the exact word (via index_exact_words) automatically. So an exact match, matches both, and ranks higher.

    Can do the same manually by searching for say

    messi | =messi

    (which is similar to what expand_keywords does internally)