Search code examples
.netlucenelucene.netlucene-highlighter

Get starting and end index of a highlighted fragment in a searched field


"My search returns a highlighted fragment from a field. I want to know that in that field of particular searched document, where does that fragment starts and ends ?"

for instance.

consider i am searching "highlighted fragment" in above lines (consider the above para as single document).

I am setting my fragmenter as :

SimpleFragmenter fragmenter = 
            new SimpleFragmenter(30);

now the output of GetBestFragment is somewhat like : "returns a highlighted fragment from"

Is it possible to get the starting and ending index of this fragment in the text above (say starting is 10 and ending is 45)


Solution

  • The Highlighter does not returns that information when you use the methods getBestFragment. Behind the scene the Highlighter uses the TokenGroup class to get the start and the end index of each fragment. You could probably use that class.