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