0

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?

Andy Preston
  • 779
  • 4
  • 9
  • 23

1 Answers1

0

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.

Andy Preston
  • 779
  • 4
  • 9
  • 23
  • 1
    To 'explain' a bit, you have 0 as query mode, so it NOT using the full index settings in interpreting the 'keywords'. Your 'search' index probably has 'expand_keywords' or even 'enable_star=0' or whatever to enable part word matches. But SNIPPETS call is ignoring all this and accepting plain list of words (it has it own syntex like CALL KEYWORDS, but does support its own basic wildcard). Should be able to use `1 as query_mode`, to make it work as well - ie the $keywords would be interpreted same was as MATCH() – barryhunter Feb 18 '20 at 13:50