Index: lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java =================================================================== --- lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java (revision 1458938) +++ lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java (working copy) @@ -35,6 +35,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; @@ -748,4 +749,54 @@ ir.close(); dir.close(); } + + public void testMultipleDocs() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); + iwc.setMergePolicy(newLogMergePolicy()); + RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc); + + FieldType offsetsType = new FieldType(TextField.TYPE_STORED); + offsetsType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); + + int numDocs = atLeast(100); + for(int i=0;ifield was indexed without * {@link IndexOptions#DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS} */ - public Map highlightFields(String fields[], Query query, IndexSearcher searcher, int[] docids, int maxPassages) throws IOException { + public Map highlightFields(String fields[], Query query, IndexSearcher searcher, int[] docidsIn, int maxPassages) throws IOException { final IndexReader reader = searcher.getIndexReader(); query = rewrite(query); SortedSet queryTerms = new TreeSet(); @@ -284,6 +284,10 @@ BreakIterator bi = (BreakIterator)breakIterator.clone(); + // Make our own copy because we sort in-place: + int[] docids = new int[docidsIn.length]; + System.arraycopy(docidsIn, 0, docids, 0, docidsIn.length); + // sort for sequential io Arrays.sort(docids); Arrays.sort(fields); @@ -302,8 +306,8 @@ Map fieldHighlights = highlightField(field, contents[i], bi, terms, docids, leaves, maxPassages); String[] result = new String[docids.length]; - for (int j = 0; j < docids.length; j++) { - result[j] = fieldHighlights.get(docids[j]); + for (int j = 0; j < docidsIn.length; j++) { + result[j] = fieldHighlights.get(docidsIn[j]); } highlights.put(field, result); }