Highlighting QueryVisitor & SpanQueryConverter [LUCENE-8160]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
Frustratingly we still don't have a Query visitor API in Lucene ( #4114 ) so I took a basic stab at it within the confines of the UnifiedHighlighter. This patch is more of a simple pragmatic solution for the UH than it is for the wholistic goals of #4114 (that would likely change Query itself). Today the UH has one massive if-else Query branch – MultiTermHighlighting, plus it re-uses WeightedSpanTermExtractor (WSTE) from the original Highlighter in a rather hacky way. In this patch I introduce QueryVisitor.java to the UH that has the massive instanceof branches in it with many places to subclass. I modified MultiTermHighlighting to use it and I modified PhraseHelper as well to wean itself off of WSTE. Interestingly PhraseHelper needed to instantiate this a second time since it needed to separately look to see if the SpanQuery contained a SpanMultiTermQueryWrapper. QueryVisitor and some usage sites contain numerous TODOs to elicit some conversation in a code review about the approach.
To fully wean the UH off of WSTE, I also added a SpanQueryConverter for converting PhraseQuery and MultiPhraseQuery. Again I also conservatively added it to the highlighter module even though it's of a general nature.
Although the patch "works", it needs cleanup and feedback.
CC @romseygeek @jimczi
---
Migrated from [LUCENE-8160](https://issues.apache.org/jira/browse/LUCENE-8160) by David Smiley (@dsmiley)
Attachments: [LUCENE-8160_UH_query_visitor.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8160/LUCENE-8160_UH_query_visitor.patch)
Contributor guide
Assessment
This issue has not been assessed yet.