use of org.apache.lucene.search.DocIdSetIterator in project neo4j by neo4j.
the class LucenePartitionAllDocumentsReader method iterateAllDocs.
private DocIdSetIterator iterateAllDocs() {
Bits liveDocs = MultiFields.getLiveDocs(reader);
DocIdSetIterator allDocs = DocIdSetIterator.all(reader.maxDoc());
if (liveDocs == null) {
return allDocs;
}
return new FilteredDocIdSetIterator(allDocs) {
@Override
protected boolean match(int doc) {
return liveDocs.get(doc);
}
};
}
use of org.apache.lucene.search.DocIdSetIterator in project neo4j by neo4j.
the class DocValuesCollector method replayTo.
private void replayTo(Collector collector) throws IOException {
for (MatchingDocs docs : getMatchingDocs()) {
LeafCollector leafCollector = collector.getLeafCollector(docs.context);
Scorer scorer;
DocIdSetIterator idIterator = docs.docIdSet.iterator();
if (isKeepScores()) {
scorer = new ReplayingScorer(docs.scores);
} else {
scorer = new ConstantScoreScorer(null, Float.NaN, idIterator);
}
leafCollector.setScorer(scorer);
int doc;
while ((doc = idIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
leafCollector.collect(doc);
}
}
}
use of org.apache.lucene.search.DocIdSetIterator in project neo4j by neo4j.
the class DocValuesCollectorTest method shouldCollectOneMatchingDocsPerSegment.
@Test
public void shouldCollectOneMatchingDocsPerSegment() throws Exception {
// given
DocValuesCollector collector = new DocValuesCollector();
IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
// when
collector.doSetNextReader(readerStub.getContext());
collector.collect(1);
collector.collect(3);
collector.doSetNextReader(readerStub.getContext());
collector.collect(5);
collector.collect(9);
// then
assertEquals(4, collector.getTotalHits());
List<DocValuesCollector.MatchingDocs> allMatchingDocs = collector.getMatchingDocs();
assertEquals(2, allMatchingDocs.size());
DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs.get(0);
assertSame(readerStub.getContext(), matchingDocs.context);
assertEquals(2, matchingDocs.totalHits);
DocIdSetIterator idIterator = matchingDocs.docIdSet.iterator();
assertEquals(1, idIterator.nextDoc());
assertEquals(3, idIterator.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc());
matchingDocs = allMatchingDocs.get(1);
assertSame(readerStub.getContext(), matchingDocs.context);
assertEquals(2, matchingDocs.totalHits);
idIterator = matchingDocs.docIdSet.iterator();
assertEquals(5, idIterator.nextDoc());
assertEquals(9, idIterator.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc());
}
use of org.apache.lucene.search.DocIdSetIterator in project neo4j by neo4j.
the class DocValuesCollectorTest method shouldCollectAllHitsPerSegment.
@Test
public void shouldCollectAllHitsPerSegment() throws Exception {
// given
DocValuesCollector collector = new DocValuesCollector();
IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
// when
collector.doSetNextReader(readerStub.getContext());
collector.collect(1);
collector.collect(3);
collector.collect(5);
collector.collect(9);
// then
assertEquals(4, collector.getTotalHits());
List<DocValuesCollector.MatchingDocs> allMatchingDocs = collector.getMatchingDocs();
assertEquals(1, allMatchingDocs.size());
DocValuesCollector.MatchingDocs matchingDocs = allMatchingDocs.get(0);
assertSame(readerStub.getContext(), matchingDocs.context);
assertEquals(4, matchingDocs.totalHits);
DocIdSetIterator idIterator = matchingDocs.docIdSet.iterator();
assertEquals(1, idIterator.nextDoc());
assertEquals(3, idIterator.nextDoc());
assertEquals(5, idIterator.nextDoc());
assertEquals(9, idIterator.nextDoc());
assertEquals(DocIdSetIterator.NO_MORE_DOCS, idIterator.nextDoc());
}
use of org.apache.lucene.search.DocIdSetIterator in project greplin-lucene-utils by Cue.
the class FixedBitSets method asList.
/**
* Converts a fixed bit set to a list.
* @param bitSet the bit set to convert.
* @return the list of matching document ids.
*/
public static List<Integer> asList(final FixedBitSet bitSet) {
DocIdSetIterator it = bitSet.iterator();
List<Integer> ints = Lists.newArrayList();
try {
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
ints.add(it.docID());
}
} catch (IOException e) {
throw new RuntimeException("Impossible IOException when iterating in memory");
}
return ints;
}
Aggregations