0

Can anyone tell me if there is a way to highlight a phrase with a single highlight using the lucene .net QueryParser?

For Eg I have the text:- The quick fox jumped over the wall.

I search for: "Quick fox" The highlights returned by lucene.net

The <>quick<> <>fox<> jumped over the wall.

QueryParser parser = new QueryParser(Version.LUCENE_30, "DocumentText", this.analyzer);
Query query;
query = parser.Parse(searchTerm);
QueryScorer scorer = new QueryScorer(query);
IFormatter formatter = new SimpleHTMLFormatter("<>", "<>");
SimpleFragmenter fragmenter = new SimpleFragmenter(int.MaxValue - 1);
Highlighter highlighter = new Highlighter(formatter, scorer);
highlighter.TextFragmenter = fragmenter;
highlighter.MaxDocCharsToAnalyze = int.MaxValue;
StringBuilder hitHighlights = new StringBuilder();
this.stream = this.analyzer.TokenStream(string.Empty, this.documentStringReader);
string highlights = highlighter.GetBestFragments(this.stream, documentTextChunk, 0, "."); 

Is there a way to return a single tag around the phrase Eg:-

The <>quick fox<> jumped over the wall.

Thanks, Vineet

Vineet
  • 401
  • 5
  • 15

1 Answers1

0

hi friends! i have read your problems.

May be you don't understand lucene bottom theory .

Every sentence during indexing , it will be analyzerd to lots of tokens , every

token is a smallest unit , whether indexing or searching .

so , only "quick fox" become a whole token, it can be highlighted <>quick fox<> then . How can ability let him become a whole ?

it has a relationship and your analyzer !

about lucene analysis

Qin Dong Liang
  • 415
  • 3
  • 12
  • https://lucidworks.com/blog/highlighting-highlighter-thoughts/ . There is a way to do this using the SpanScorer as described in this link. However I am not able to get this to work with lucene.net. The same way phrase searches are found while searching, highlighting is also possible as a single block. – Vineet Aug 03 '15 at 11:59