Stinger
Stinger

Reputation: 160

Get list of terms that were highlighted by Solr

When I search for the word "fish" I get back a list of documents containing that word and variants of that word. If I turn on highlighting I might see a snippet that looks like this: The law requires that anyone <em>fishing</em> in public lakes...

I would like to show the user the above snippet, which works just fine by the way, but I would also like to show the user a complete list of words that would also have been highlighted had I shown all snippets.

For example I would like to be able to show the user the following:

Section 18.32A - Hunting and Fishing ...The law requires that anyone <em>fishing</em> in public lakes... Document also contains: Fish, Fishing, Fisherman

Is thee a way to get that list of words other than having solr highlight the entire document and then me parsing the document looking for em tags and building a list of highlighted words?

Upvotes: 3

Views: 439

Answers (1)

Elaine Blount
Elaine Blount

Reputation: 11

I would investigate frag size (hl.fragsize), synonyms (synonym.txt), or stemming (can help with variations of a word) to find a solution. You can set fish, fishing, fished to all mean the same in synonyms. Ensure you understand how the expand all works and whether you want the search to replace each with the other. Also ensure you know whether to index the synonym file or query with it. Do not use synonyms at both index and query time. There is also a switch to enable multiple matches in highlighting.

Upvotes: 1

Related Questions