maxLength is negative or Integer.MAX_VALUE
*/
public PostingsHighlighter(int maxLength) {
- this(maxLength, BreakIterator.getSentenceInstance(Locale.ROOT), new PassageScorer(), new PassageFormatter());
+ this(maxLength, BreakIterator.getSentenceInstance(Locale.ROOT));
}
/**
@@ -122,11 +120,9 @@
* @param breakIterator used for finding passage
* boundaries; pass null to highlight the entire
* content as a single Passage.
- * @param scorer used for ranking passages.
- * @param formatter used for formatting passages into highlighted snippets.
* @throws IllegalArgumentException if maxLength is negative or Integer.MAX_VALUE
*/
- public PostingsHighlighter(int maxLength, BreakIterator breakIterator, PassageScorer scorer, PassageFormatter formatter) {
+ public PostingsHighlighter(int maxLength, BreakIterator breakIterator) {
if (maxLength < 0 || maxLength == Integer.MAX_VALUE) {
// two reasons: no overflow problems in BreakIterator.preceding(offset+1),
// our sentinel in the offsets queue uses this value to terminate.
@@ -135,15 +131,28 @@
if (breakIterator == null) {
breakIterator = new WholeBreakIterator();
}
- if (scorer == null || formatter == null) {
- throw new NullPointerException();
- }
this.maxLength = maxLength;
this.breakIterator = breakIterator;
- this.scorer = scorer;
- this.formatter = formatter;
}
+ /** Returns the {@link PassageFormatter} to use for
+ * formatting passages into highlighted snippets. This
+ * returns a new {@code PassageFormatter} by default;
+ * subclasses can override to customize. */
+ protected PassageFormatter getFormatter(String field) {
+ // nocommit can we do this just once & reuse across fields?
+ return new PassageFormatter();
+ }
+
+ /** Returns the {@link PassageScorer} to use for
+ * ranking passages. This
+ * returns a new {@code PassageScorer} by default;
+ * subclasses can override to customize. */
+ protected PassageScorer getScorer(String field) {
+ // nocommit can we do this just once & reuse across fields?
+ return new PassageScorer();
+ }
+
/**
* Highlights the top passages from a single field.
*
@@ -302,7 +311,13 @@
Term ceiling = new Term(field, UnicodeUtil.BIG_TERM);
SortedSet* Only {@link #getNumMatches()} are valid. */ - public Term[] getMatchTerms() { + public BytesRef[] getMatchTerms() { return matchTerms; } }