You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/10/25 20:31:51 UTC

[GitHub] [lucene] dsmiley commented on a change in pull request #412: LUCENE-10197: UnifiedHighlighter should use builders for thread-safety

dsmiley commented on a change in pull request #412:
URL: https://github.com/apache/lucene/pull/412#discussion_r735937665



##########
File path: lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighter.java
##########
@@ -638,6 +674,39 @@ protected BreakIterator getBreakIterator(String field) {
     ir.close();
   }
 
+  // This is a copy of testHighlightAllText() where UnifiedHighlighter is created using a builder.
+  public void testHighlightAllTextUsingBuilder() throws Exception {

Review comment:
       Why duplicate a test for this?  Builders don't need to be tested directly; they will in-effect be tested indirectly by tests using them naturally.  Even if that isn't perfect; I wouldn't bother.  Furthermore I'm dubious that you needed to add the other tests in this PR.

##########
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:
       Aha; I assume this is for subclassing the builder.  I think for this to work properly, Builder would need to be generic, otherwise there's not much point?  Maybe you'll explore that.




-- 
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-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org