use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class SimpleIndexReaderTest method scanQueryReachSearcher.
@Test
public void scanQueryReachSearcher() throws Exception {
IndexReader simpleIndexReader = getUniqueSimpleReader();
simpleIndexReader.query(IndexQuery.exists(1));
verify(indexSearcher).search(any(MatchAllDocsQuery.class), any(DocValuesCollector.class));
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method addUpdates.
@Test
public void addUpdates() throws Exception {
populator = newPopulator();
List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, descriptor.schema(), "aaa"), IndexEntryUpdate.add(2, descriptor.schema(), "bbb"), IndexEntryUpdate.add(3, descriptor.schema(), "ccc"));
populator.add(updates);
index.maybeRefreshBlocking();
try (IndexReader reader = index.getIndexReader()) {
PrimitiveLongIterator allEntities = reader.query(IndexQuery.exists(1));
assertArrayEquals(new long[] { 1, 2, 3 }, PrimitiveLongCollections.asArray(allEntities));
}
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class LuceneSchemaIndexPopulationIT method partitionedIndexPopulation.
@Test
public void partitionedIndexPopulation() throws Exception {
try (SchemaIndex uniqueIndex = LuceneSchemaIndexBuilder.create(descriptor).withFileSystem(fileSystemRule.get()).withIndexRootFolder(testDir.directory("partitionIndex" + affectedNodes)).withIndexIdentifier("uniqueIndex" + affectedNodes).build()) {
uniqueIndex.open();
// index is empty and not yet exist
assertEquals(0, uniqueIndex.allDocumentsReader().maxCount());
assertFalse(uniqueIndex.exists());
try (LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor(uniqueIndex, descriptor)) {
generateUpdates(indexAccessor, affectedNodes);
indexAccessor.force();
// now index is online and should contain updates data
assertTrue(uniqueIndex.isOnline());
try (IndexReader indexReader = indexAccessor.newReader()) {
long[] nodes = PrimitiveLongCollections.asArray(indexReader.query(IndexQuery.exists(1)));
assertEquals(affectedNodes, nodes.length);
IndexSampler indexSampler = indexReader.createSampler();
IndexSample sample = indexSampler.sampleIndex();
assertEquals(affectedNodes, sample.indexSize());
assertEquals(affectedNodes, sample.uniqueValues());
assertEquals(affectedNodes, sample.sampleSize());
}
}
}
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class DatabaseCompositeIndexAccessorTest method indexReaderShouldSupportScan.
@Test
public void indexReaderShouldSupportScan() throws Exception {
// GIVEN
updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
IndexReader reader = accessor.newReader();
// WHEN
PrimitiveLongIterator results = reader.query(IndexQuery.exists(PROP_ID1), IndexQuery.exists(PROP_ID2));
// THEN
assertEquals(asSet(nodeId, nodeId2), PrimitiveLongCollections.toSet(results));
assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID1, values[0]), IndexQuery.exact(PROP_ID2, values[1]))));
reader.close();
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class DatabaseCompositeIndexAccessorTest method canRemoveExistingData.
@Test
public void canRemoveExistingData() throws Exception {
// GIVEN
updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
// WHEN
updateAndCommit(asList(remove(nodeId, values)));
IndexReader reader = accessor.newReader();
// THEN
assertEquals(asSet(nodeId2), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID1, values2[0]), IndexQuery.exact(PROP_ID2, values2[1]))));
assertEquals(asSet(), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID1, values[0]), IndexQuery.exact(PROP_ID2, values[1]))));
reader.close();
}
Aggregations