Search in sources :

Example 1 with PartitionSearcher

use of org.neo4j.kernel.api.impl.index.partition.PartitionSearcher in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldCreateNewDocumentsForNewlyLabeledNodes.

@Test
public void shouldCreateNewDocumentsForNewlyLabeledNodes() throws Exception {
    // given
    WritableIndexPartition partition = mock(WritableIndexPartition.class);
    WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    when(partition.acquireSearcher()).thenReturn(partitionSearcher);
    IndexWriter indexWriter = mock(IndexWriter.class);
    when(partition.getIndexWriter()).thenReturn(indexWriter);
    IndexSearcher searcher = mock(IndexSearcher.class);
    when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
    when(searcher.search(new TermQuery(format.rangeTerm(0)), 1)).thenReturn(emptyTopDocs());
    when(searcher.search(new TermQuery(format.rangeTerm(1)), 1)).thenReturn(null);
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(), labels(6, 7)));
    writer.write(labelChanges(1, labels(), labels(6, 8)));
    writer.write(labelChanges(1 << format.bitmapFormat().shift, labels(), labels(7)));
    writer.close();
    // then
    verify(partition, times(2)).acquireSearcher();
    verify(partitionSearcher, times(2)).getIndexSearcher();
    verify(partition, times(2)).getIndexWriter();
    verify(partitionSearcher, times(2)).close();
    verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(6, 0x3), format.labelField(7, 0x1), format.labelField(8, 0x2), format.labelSearchField(8))));
    verify(indexWriter).updateDocument(eq(format.rangeTerm(1)), match(document(format.rangeField(1), format.labelField(7, 0x1), format.labelSearchField(7))));
    verify(index).maybeRefreshBlocking();
    verifyNoMoreInteractions(partition);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 2 with PartitionSearcher

use of org.neo4j.kernel.api.impl.index.partition.PartitionSearcher in project neo4j by neo4j.

the class LuceneLabelScanIndex method createSimpleReader.

private LabelScanReader createSimpleReader(List<AbstractIndexPartition> partitions) throws IOException {
    AbstractIndexPartition partition = getFirstPartition(partitions);
    PartitionSearcher searcher = partition.acquireSearcher();
    return new SimpleLuceneLabelScanStoreReader(searcher, storageStrategy);
}
Also used : PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition) SimpleLuceneLabelScanStoreReader(org.neo4j.kernel.api.impl.labelscan.reader.SimpleLuceneLabelScanStoreReader)

Example 3 with PartitionSearcher

use of org.neo4j.kernel.api.impl.index.partition.PartitionSearcher in project neo4j by neo4j.

the class SimpleUniquenessVerifierTest method partitionSearcherIsClosed.

@Test
void partitionSearcherIsClosed() throws IOException {
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    SimpleUniquenessVerifier verifier = new SimpleUniquenessVerifier(partitionSearcher);
    verifier.close();
    verify(partitionSearcher).close();
}
Also used : SimpleUniquenessVerifier(org.neo4j.kernel.api.impl.schema.verification.SimpleUniquenessVerifier) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) Test(org.junit.jupiter.api.Test)

Example 4 with PartitionSearcher

use of org.neo4j.kernel.api.impl.index.partition.PartitionSearcher in project neo4j by neo4j.

the class PartitionedLuceneLabelScanWriter method flush.

private void flush() throws IOException {
    if (currentRange < 0) {
        return;
    }
    AbstractIndexPartition partition = getCurrentPartition();
    try (PartitionSearcher partitionSearcher = partition.acquireSearcher()) {
        IndexSearcher searcher = partitionSearcher.getIndexSearcher();
        Map<Long, Bitmap> /*label*/
        fields = readLabelBitMapsInRange(searcher, currentRange);
        updateFields(updates, fields);
        Document document = new Document();
        format.addRangeValuesField(document, currentRange);
        for (Map.Entry<Long, Bitmap> /*label*/
        field : fields.entrySet()) {
            // one field per label
            Bitmap value = field.getValue();
            if (value.hasContent()) {
                format.addLabelAndSearchFields(document, field.getKey(), value);
            }
        }
        if (isEmpty(document)) {
            partition.getIndexWriter().deleteDocuments(format.rangeTerm(document));
        } else {
            partition.getIndexWriter().updateDocument(format.rangeTerm(document), document);
        }
        updates.clear();
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) Document(org.apache.lucene.document.Document) HashMap(java.util.HashMap) Map(java.util.Map) AbstractIndexPartition(org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)

Example 5 with PartitionSearcher

use of org.neo4j.kernel.api.impl.index.partition.PartitionSearcher in project neo4j by neo4j.

the class LuceneLabelScanStoreWriterTest method newStubPartitionSearcher.

private static PartitionSearcher newStubPartitionSearcher(Map<Term, Document> storage) {
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    when(partitionSearcher.getIndexSearcher()).thenReturn(new StubIndexSearcher(storage));
    return partitionSearcher;
}
Also used : PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)

Aggregations

PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)9 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)3 TermQuery (org.apache.lucene.search.TermQuery)2 Test (org.junit.Test)2 AbstractIndexPartition (org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)2 SimpleUniquenessVerifier (org.neo4j.kernel.api.impl.schema.verification.SimpleUniquenessVerifier)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Document (org.apache.lucene.document.Document)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 CollectionTerminatedException (org.apache.lucene.search.CollectionTerminatedException)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 Test (org.junit.jupiter.api.Test)1 FirstHitCollector (org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)1 Neo4jIndexSearcher (org.neo4j.kernel.api.impl.index.partition.Neo4jIndexSearcher)1 WritableDatabaseLabelScanIndex (org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex)1 Bitmap (org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap)1