sphinxsphinxql

Sphinx, snippets and partial word matches


We're using sphinx and snippets to do a basic site search.

SELECT id FROM search WHERE MATCH('(@keywords corona)')

And we're getting matches on "coronavirus" and "coronary" like we would expect.

But when we later use

CALL SNIPPETS(
    'Wuhan Novel Coronavirus - What you need to know',
    'search',
    'corona',
    '<span class="mark">' AS before_match,
    '</span>' AS after_match,
    '…' AS chunk_separator,
    800 AS limit,
    20 AS around,
    0 AS query_mode
)

None of these partial matches are being highlighted.

If we search for a full word (replacing "corona" in the SELECT and CALL SNIPPETS with e.g. "coronavirus") then the full word results are highlighted correctly.

Is there a way we can get CALL SNIPPETS to highlight the partial word matches in the first example like it does with the full word results in the second example?


Solution

  • I just appended "*" to the keyword in CALL SNIPPETS like this:

        'Wuhan Novel Coronavirus - What you need to know',
        'search',
        '*corona*',
        800 AS limit,
        20 AS around,
        0 AS query_mode
    

    But the comment from @barryhunter below makes more sense than my actual solution.