Search in sources :

Example 6 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 7 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)

Example 8 with PartitionSearcher

use of org.neo4j.kernel.api.impl.index.partition.PartitionSearcher 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)

Example 9 with PartitionSearcher

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

the class LuceneAllDocumentsReaderTest method createPartitionSearcher.

private static PartitionSearcher createPartitionSearcher(int maxDoc, int partition, int maxSize) throws IOException {
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    IndexSearcher indexSearcher = mock(IndexSearcher.class);
    IndexReader indexReader = mock(IndexReader.class);
    when(partitionSearcher.getIndexSearcher()).thenReturn(indexSearcher);
    when(indexSearcher.getIndexReader()).thenReturn(indexReader);
    when(indexReader.maxDoc()).thenReturn(maxDoc);
    when(indexSearcher.doc(0)).thenReturn(createDocument(uniqueDocValue(1, partition, maxSize)));
    when(indexSearcher.doc(1)).thenReturn(createDocument(uniqueDocValue(2, partition, maxSize)));
    when(indexSearcher.doc(2)).thenReturn(createDocument(uniqueDocValue(3, partition, maxSize)));
    return partitionSearcher;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) IndexReader(org.apache.lucene.index.IndexReader)

Example 10 with PartitionSearcher

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

the class SimpleUniquenessVerifierTest method runUniquenessVerification.

private void runUniquenessVerification(PropertyAccessor propertyAccessor, IndexSearcher indexSearcher) throws IOException, IndexEntryConflictException {
    try {
        PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
        when(partitionSearcher.getIndexSearcher()).thenReturn(indexSearcher);
        try (UniquenessVerifier verifier = new SimpleUniquenessVerifier(partitionSearcher)) {
            verifier.verify(propertyAccessor, PROPERTY_KEY_IDS);
        }
    } finally {
        searcherManager.release(indexSearcher);
    }
}
Also used : UniquenessVerifier(org.neo4j.kernel.api.impl.schema.verification.UniquenessVerifier) SimpleUniquenessVerifier(org.neo4j.kernel.api.impl.schema.verification.SimpleUniquenessVerifier) SimpleUniquenessVerifier(org.neo4j.kernel.api.impl.schema.verification.SimpleUniquenessVerifier) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)

Aggregations

PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)11 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 AbstractIndexPartition (org.neo4j.kernel.api.impl.index.partition.AbstractIndexPartition)4 Test (org.junit.Test)3 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)3 SimpleUniquenessVerifier (org.neo4j.kernel.api.impl.schema.verification.SimpleUniquenessVerifier)3 TermQuery (org.apache.lucene.search.TermQuery)2 File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)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 FirstHitCollector (org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)1