apanimesh061 commented on a change in pull request #412:
URL: https://github.com/apache/lucene/pull/412#discussion_r737860855
##########
File path:
lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java
##########
@@ -143,6 +143,106 @@
private int cacheFieldValCharsThreshold = DEFAULT_CACHE_CHARS_THRESHOLD;
+ /** Builder for UnifiedHighlighter. */
+ public abstract static class Builder<T extends Builder<T>> {
+ private IndexSearcher searcher;
+ private 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 T withSearcher(IndexSearcher value) {
+ this.searcher = value;
+ return self();
+ }
+
+ public T withIndexAnalyzer(Analyzer value) {
+ this.indexAnalyzer = value;
+ return self();
+ }
+
+ public T withHandleMultiTermQuery(boolean value) {
+ this.handleMultiTermQuery = value;
+ return self();
+ }
+
+ public T withHighlightPhrasesStrictly(boolean value) {
+ this.highlightPhrasesStrictly = value;
+ return self();
+ }
+
+ public T withPassageRelevancyOverSpeed(boolean value) {
+ this.passageRelevancyOverSpeed = value;
+ return self();
+ }
+
+ public T 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 T withBreakIterator(Supplier<BreakIterator> value) {
+ this.breakIterator = value;
+ return self();
+ }
+
+ public T withFieldMatcher(Predicate<String> value) {
+ this.fieldMatcher = value;
+ return self();
+ }
+
+ public T withScorer(PassageScorer value) {
+ this.scorer = value;
+ return self();
+ }
+
+ public T withFormatter(PassageFormatter value) {
+ this.formatter = value;
+ return self();
+ }
+
+ public T withMaxNoHighlightPassages(int value) {
+ this.maxNoHighlightPassages = value;
+ return self();
+ }
+
+ public T withCacheFieldValCharsThreshold(int value) {
+ this.cacheFieldValCharsThreshold = value;
+ return self();
+ }
+
+ protected abstract T self();
+
+ public UnifiedHighlighter build() {
+ return new UnifiedHighlighter(this);
+ }
+ }
+
+ // Why?
https://web.archive.org/web/20150920054846/https://weblogs.java.net/node/642849
Review comment:
@dsmiley ah yes you are right. Thanks for rerunning the tests.
Does the new builder class look right to you? Is it expected to remove all
setters from this class? This would mean I'll have to modify all their
references in other classes and unit tests and replace them with builders.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]