final IndexSearcher indexSearcher = newSearcher(indexReader);
try {
final Query phraseQuery = new SpanNearQuery(new SpanQuery[] {
new SpanTermQuery(new Term(FIELD, "fox")),
new SpanTermQuery(new Term(FIELD, "jumped")) }, 0, true);
final OpenBitSet bitset = new OpenBitSet();
indexSearcher.search(phraseQuery, new Collector() {
private int baseDoc;
@Override
public boolean acceptsDocsOutOfOrder() {
return true;
}
@Override
public void collect(int i) throws IOException {
bitset.set(this.baseDoc + i);
}
@Override
public void setNextReader(IndexReader indexreader, int i)
throws IOException {
this.baseDoc = i;
}
@Override
public void setScorer(org.apache.lucene.search.Scorer scorer)
throws IOException {
// Do Nothing
}
});
assertEquals(1, bitset.cardinality());
final Highlighter highlighter = new Highlighter(
new SimpleHTMLFormatter(), new SimpleHTMLEncoder(),
new QueryScorer(phraseQuery));
for (int position = bitset.nextSetBit(0); position >= 0; position = bitset
.nextSetBit(position + 1)) {
assertEquals(0, position);
final TokenStream tokenStream = TokenSources.getTokenStream(
(TermPositionVector) indexReader.getTermFreqVector(position,
FIELD), false);