0

i am trying to do highlighting on multifields using a booleanquery with multiple clauses in lucene.net (version 3.0.3 or 4.8.0-beta00014).

Sample document inside an index would be like: {Document<stored,indexed,termVector<pID:bgz3301011900> stored,indexed,tokenized<lastname:morgan> stored,indexed,tokenized<firstname:katarina> stored,indexed,tokenized<gender:f> stored,indexed,tokenized<age:21> stored,indexed,tokenized<text: there are many kinds of apples and more>>}

BooleanQuery is like: {+(lastname:mor*) +(text:apple text:apple~2)}

When doing the highlighting it will result in highlighting morgan in the lastname field, but also it will highlight more in the text field (since it is a wildcard search). I had a few ideas on how to do seperate highlighting for each clause that will work only on it's own field, but all resulted in a slower code, so I was wondering don't lucene has something which will do that automatically, or am I missing something here.

Thanks for the help.

  • Like [this `Lucene.Net.Highligher` test](https://github.com/apache/lucenenet/blob/03bc03bb5bcb74d12524cc9c0d85e501473a4445/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterTest.cs#L277-L328)? While the documentation leaves much to be desired, there are many examples to look through in the tests of how to do highlighting. Also, you may want to check out [this question](https://stackoverflow.com/q/30684461) and [this article](https://discuss.elastic.co/t/multi-field-and-highlighting/12329). After all, Elastic Search just uses Lucene under the hood. – NightOwl888 Nov 08 '21 at 23:31
  • Thanks for the info, but it was a bit late, although I have already tried the first solution you linked in your comment and for some reason it didn't work for me. Anyway, I ended up solving it by dividing the query into several queries and then loop over them to do the highlighting. But still, I don't think this is a very good solution. – user16929345 Nov 16 '21 at 08:31

0 Answers0