Apache Lucene open-source search software
LUCENE-6271: fix postingshighlighter check
Robert Muir087781fc9c12
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java b/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.javaindex 98c3bacd498..e5204609cdd 100644--- a/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java+++ b/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java@@ -504,6 +504,10 @@ public class PostingsHighlighter {// if the segment has changed, we must initialize new enums.if (leaf != lastLeaf) {Terms t = r.terms(field);+ if (!t.hasOffsets()) {+ // no offsets available+ throw new IllegalArgumentException("field '" + field + "' was indexed without offsets, cannot highlight");+ }if (t != null) {termsEnum = t.iterator(null);postings = new PostingsEnum[terms.length];@@ -559,12 +563,8 @@ public class PostingsHighlighter {if (!termsEnum.seekExact(terms[i])) {continue; // term not found}- // nocommit: checkde = postings[i] = termsEnum.postings(null, null, PostingsEnum.OFFSETS);- if (de == null) {- // no positions available- throw new IllegalArgumentException("field '" + field + "' was indexed without offsets, cannot highlight");- }+ assert de != null;pDoc = de.advance(doc);} else {pDoc = de.docID();@@ -600,9 +600,7 @@ public class PostingsHighlighter {while ((off = pq.poll()) != null) {final PostingsEnum dp = off.dp;int start = dp.startOffset();- if (start == -1) {- throw new IllegalArgumentException("field '" + field + "' was indexed without offsets, cannot highlight");- }+ assert start >= 0;int end = dp.endOffset();// LUCENE-5166: this hit would span the content limit... however more valid// hits may exist (they are sorted by start). so we pretend like we never