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();
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations