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



##########
File path: 
lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java
##########
@@ -113,118 +112,239 @@
   protected static final LabelledCharArrayMatcher[] ZERO_LEN_AUTOMATA_ARRAY =
       new LabelledCharArrayMatcher[0];
 
-  protected final IndexSearcher searcher; // if null, can only use 
highlightWithoutSearcher
+  protected final IndexSearcher searcher;
 
   protected final Analyzer indexAnalyzer;
 
-  private boolean defaultHandleMtq = true; // e.g. wildcards
+  private final int maxLength;
 
-  private boolean defaultHighlightPhrasesStrictly = true; // AKA "accuracy" or 
"query debugging"
+  private final Supplier<BreakIterator> defaultBreakIterator;
 
-  // For analysis, prefer MemoryIndexOffsetStrategy
-  private boolean defaultPassageRelevancyOverSpeed = true;
+  private final Predicate<String> defaultFieldMatcher;
 
-  private int maxLength = DEFAULT_MAX_LENGTH;
+  private final PassageScorer defaultScorer;
 
-  // BreakIterator is stateful so we use a Supplier factory method
-  private Supplier<BreakIterator> defaultBreakIterator =
-      () -> BreakIterator.getSentenceInstance(Locale.ROOT);
+  private final PassageFormatter defaultFormatter;
 
-  private Predicate<String> defaultFieldMatcher;
+  private final int defaultMaxNoHighlightPassages;
 
-  private PassageScorer defaultScorer = new PassageScorer();
+  // lazy initialized with double-check locking; protected so subclass can init
+  protected volatile FieldInfos fieldInfos;
 
-  private PassageFormatter defaultFormatter = new DefaultPassageFormatter();
+  private final int cacheFieldValCharsThreshold;
 
-  private int defaultMaxNoHighlightPassages = -1;
+  private final Set<HighlightFlag> flags;
 
-  // lazy initialized with double-check locking; protected so subclass can init
-  protected volatile FieldInfos fieldInfos;
+  /** Builder for UnifiedHighlighter. */
+  public static class Builder {
+    /** If null, can only use highlightWithoutSearcher. */
+    private IndexSearcher searcher;
 
-  private int cacheFieldValCharsThreshold = DEFAULT_CACHE_CHARS_THRESHOLD;
+    private Analyzer indexAnalyzer;
+    private boolean handleMultiTermQuery = true;
+    private boolean highlightPhrasesStrictly = true;
+    private boolean passageRelevancyOverSpeed = true;
+    private boolean weightMatches = true;
+    private int maxLength = DEFAULT_MAX_LENGTH;
 
-  /** Extracts matching terms after rewriting against an empty index */
-  protected static Set<Term> extractTerms(Query query) throws IOException {
-    Set<Term> queryTerms = new HashSet<>();
-    
EMPTY_INDEXSEARCHER.rewrite(query).visit(QueryVisitor.termCollector(queryTerms));
-    return queryTerms;
-  }
+    /** BreakIterator is stateful so we use a Supplier factory method. */
+    private Supplier<BreakIterator> breakIterator =
+        () -> BreakIterator.getSentenceInstance(Locale.ROOT);
 
-  /**
-   * Constructs the highlighter with the given index searcher and analyzer.
-   *
-   * @param indexSearcher Usually required, unless {@link 
#highlightWithoutSearcher(String, Query,
-   *     String, int)} is used, in which case this needs to be null.
-   * @param indexAnalyzer Required, even if in some circumstances it isn't 
used.
-   */
-  public UnifiedHighlighter(IndexSearcher indexSearcher, Analyzer 
indexAnalyzer) {
-    this.searcher = indexSearcher; // TODO: make non nullable
-    this.indexAnalyzer =
-        Objects.requireNonNull(
-            indexAnalyzer,
-            "indexAnalyzer is required" + " (even if in some circumstances it 
isn't used)");
-  }
+    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;
+    private Set<HighlightFlag> flags;
 
-  public void setHandleMultiTermQuery(boolean handleMtq) {
-    this.defaultHandleMtq = handleMtq;
-  }
+    /**
+     * Usually required, unless {@link #highlightWithoutSearcher(String, 
Query, String, int)} is
+     * used, in which case this needs to be null.
+     */
+    public Builder withSearcher(IndexSearcher value) {

Review comment:
       @dsmiley 
   
   Thanks for the feedback.
   
   Would something like this work?
   
   ```
   UnifiedHighlighter unifiedHighlighter =
           UnifiedHighlighter.builder(searcher, indexAnalyzer)
               .withMaxLength(100)
               .withScorer(new PassageScorer())
               .build();
   ```
   and 
   
   ```
   UnifiedHighlighter unifiedHighlighter =
           UnifiedHighlighter.builderWithoutSearcher(indexAnalyzer)
               .withMaxLength(100)
               .withScorer(new PassageScorer())
               .build();
   ```
   
   I'll then remove `withSearcher()` and `withIndexAnalyzer()`.




-- 
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

Reply via email to