Goofing off with my index, I ran across this example
http://www.lucidimagination.com/blog/2009/05/26/accessing-words-around-a-positional-match-in-lucene/
for
using span queries to see what else is around a word that hits. Noticeably,
there's a nice getSpans(IndexReader) method that just takes in the index
reader and returns all the span objects, something not present in Lucene 4.
I'm trying to replicate this in Lucene 4.0 to see how viable it is and
despite having my span query hit on 10 documents, I cannot retrieve any
spans. The API for doing this got remarkably more complex!

My code reads as follows:
IndexReader ir = search.getIndexReader();
TermContext tmctxt = TermContext.build(ir.getTopReaderContext(),
testSpan.getTerm(), false);
Map termMap = new HashMap();
termMap.put(testSpan.getTerm(), tmctxt);
AtomicReaderContext ac = new IndexReader.AtomicReaderContext(ir);
Bits bits = new Bits.MatchAllBits(0);
Spans spans = testSpan.getSpans(ac, bits, termMap);

However, spans never returns a spans object, spans.next() always returns
false.

Am I missing anything?

Thanks!
Stephen

Reply via email to