apanimesh061 commented on a change in pull request #412: URL: https://github.com/apache/lucene/pull/412#discussion_r736079027
########## File path: lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java ########## @@ -143,6 +143,91 @@ private int cacheFieldValCharsThreshold = DEFAULT_CACHE_CHARS_THRESHOLD; + /** Builder for UnifiedHighlighter. */ + public static class Builder { + private final IndexSearcher searcher; + private final Analyzer indexAnalyzer; + private boolean handleMultiTermQuery = true; + private boolean highlightPhrasesStrictly = true; + private boolean passageRelevancyOverSpeed = true; + private int maxLength = DEFAULT_MAX_LENGTH; + private Supplier<BreakIterator> breakIterator = + () -> BreakIterator.getSentenceInstance(Locale.ROOT); + private Predicate<String> fieldMatcher; + private PassageScorer scorer = new PassageScorer(); + private PassageFormatter formatter = new DefaultPassageFormatter(); + private int maxNoHighlightPassages = -1; + private int cacheFieldValCharsThreshold = DEFAULT_CACHE_CHARS_THRESHOLD; + + public Builder(IndexSearcher searcher, Analyzer indexAnalyzer) { + this.searcher = Objects.requireNonNull(searcher); + this.indexAnalyzer = Objects.requireNonNull(indexAnalyzer); + } + + public Builder withHandleMultiTermQuery(boolean value) { + this.handleMultiTermQuery = value; + return self(); + } + + public Builder withHighlightPhrasesStrictly(boolean value) { + this.highlightPhrasesStrictly = value; + return self(); + } + + public Builder withPassageRelevancyOverSpeed(boolean value) { + this.passageRelevancyOverSpeed = value; + return self(); + } + + public Builder withMaxLength(int value) { + if (value < 0 || value == Integer.MAX_VALUE) { + // two reasons: no overflow problems in BreakIterator.preceding(offset+1), + // our sentinel in the offsets queue uses this value to terminate. + throw new IllegalArgumentException("maxLength must be < Integer.MAX_VALUE"); + } + this.maxLength = value; + return self(); + } + + public Builder withBreakIterator(Supplier<BreakIterator> value) { + this.breakIterator = value; + return self(); + } + + public Builder withFieldMatcher(Predicate<String> value) { + this.fieldMatcher = value; + return self(); + } + + public Builder withScorer(PassageScorer value) { + this.scorer = value; + return self(); + } + + public Builder withFormatter(PassageFormatter value) { + this.formatter = value; + return self(); + } + + public Builder withMaxNoHighlightPassages(int value) { + this.maxNoHighlightPassages = value; + return self(); + } + + public Builder withCacheFieldValCharsThreshold(int value) { + this.cacheFieldValCharsThreshold = value; + return self(); + } + + protected Builder self() { Review comment: Yes that was the plan. I am still working on subclassing part of it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org