Search in sources :

Example 1 with FirstHitCollector

use of org.neo4j.kernel.api.impl.index.collector.FirstHitCollector in project neo4j by neo4j.

the class PartitionedLuceneLabelScanWriter method readLabelBitMapsInRange.

private Map<Long, /*range*/
Bitmap> readLabelBitMapsInRange(IndexSearcher searcher, long range) throws IOException {
    Map<Long, Bitmap> /*label*/
    fields = new HashMap<>();
    Term documentTerm = format.rangeTerm(range);
    TermQuery query = new TermQuery(documentTerm);
    FirstHitCollector hitCollector = new FirstHitCollector();
    searcher.search(query, hitCollector);
    if (hitCollector.hasMatched()) {
        Document document = searcher.doc(hitCollector.getMatchedDoc());
        for (IndexableField field : document.getFields()) {
            if (!format.isRangeOrLabelField(field)) {
                Long label = Long.valueOf(field.name());
                fields.put(label, format.readBitmap(field));
            }
        }
    }
    return fields;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) TermQuery(org.apache.lucene.search.TermQuery) Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) HashMap(java.util.HashMap) FirstHitCollector(org.neo4j.kernel.api.impl.index.collector.FirstHitCollector) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document)

Example 2 with FirstHitCollector

use of org.neo4j.kernel.api.impl.index.collector.FirstHitCollector in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method newIndexPartitionMock.

private WritableIndexPartition newIndexPartitionMock(IndexWriter indexWriter, Document... documents) throws IOException {
    WritableIndexPartition partition = mock(WritableIndexPartition.class);
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    when(partition.acquireSearcher()).thenReturn(partitionSearcher);
    when(partition.getIndexWriter()).thenReturn(indexWriter);
    IndexSearcher searcher = mock(IndexSearcher.class);
    when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
    for (int i = 0; i < documents.length; i++) {
        int docId = i;
        doAnswer(invocation -> {
            FirstHitCollector collector = (FirstHitCollector) invocation.getArguments()[1];
            try {
                collector.collect(docId);
            } catch (CollectionTerminatedException swallow) {
            }
            return null;
        }).when(searcher).search(eq(new TermQuery(format.rangeTerm(documents[i]))), any(FirstHitCollector.class));
        when(searcher.doc(i)).thenReturn(documents[i]);
    }
    return partition;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) CollectionTerminatedException(org.apache.lucene.search.CollectionTerminatedException) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) FirstHitCollector(org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)

Aggregations

TermQuery (org.apache.lucene.search.TermQuery)2 FirstHitCollector (org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)2 HashMap (java.util.HashMap)1 Document (org.apache.lucene.document.Document)1 IndexableField (org.apache.lucene.index.IndexableField)1 Term (org.apache.lucene.index.Term)1 CollectionTerminatedException (org.apache.lucene.search.CollectionTerminatedException)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)1 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)1 Bitmap (org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap)1