Search code examples
solr

Can Solr rank its highlight snippets?


Solr will give as many highlights as I specify in hl.snippets, giving a list of highlights. What I want is the set of (2 or 3) highlight snippets that best match the query. Is there in innate Solr feature that does this?


Solution

  • The Unified Highlighter allows you to tell it how it should score the returned highlights. It should already do some scoring by default, so the first task would be switch to the unified highlighter if you're not using that.

    You can then tweak how it uses BM25 to score the returned highlights:

    hl.score.k1 [Optional] [Default: 1.2]

    Specifies BM25 term frequency normalization parameter 'k1'. For example, it can be set to 0 to rank passages solely based on the number of query terms that match.

    hl.score.b [Optional] [Default: 0.75]

    Specifies BM25 length normalization parameter 'b'. For example, it can be set to "0" to ignore the length of passages entirely when ranking.

    hl.score.pivot [Optional] [Default: 87]

    Specifies BM25 average passage length in characters.