use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class ConcurrentLuceneFulltextUpdaterTest method raceContestantsAndVerifyResults.
private void raceContestantsAndVerifyResults(Runnable aliceWork, Runnable changeConfig, Runnable bobWork) throws Throwable {
race.addContestants(aliceThreads, aliceWork);
race.addContestant(changeConfig);
race.addContestants(bobThreads, bobWork);
race.go();
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexOnline("nodes", 1, TimeUnit.MINUTES);
}
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = kernelTransaction(tx);
IndexReadSession index = ktx.dataRead().indexReadSession(ktx.schemaRead().indexGetForName("nodes"));
try (NodeValueIndexCursor bobCursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(index, bobCursor, unconstrained(), PropertyIndexQuery.fulltextSearch("bob"));
int bobCount = 0;
while (bobCursor.next()) {
bobCount += 1;
}
assertEquals(bobThreads * nodesCreatedPerThread, bobCount);
}
try (NodeValueIndexCursor aliceCursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(index, aliceCursor, unconstrained(), PropertyIndexQuery.fulltextSearch("alice"));
int aliceCount = 0;
while (aliceCursor.next()) {
aliceCount += 1;
}
assertEquals(0, aliceCount);
}
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class LuceneFulltextTestSupport method assertQueryFindsIds.
void assertQueryFindsIds(KernelTransaction ktx, boolean nodes, String indexName, String query, long... ids) throws Exception {
IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
MutableLongSet set = LongSets.mutable.of(ids);
if (nodes) {
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
while (cursor.next()) {
long nodeId = cursor.nodeReference();
assertTrue(set.remove(nodeId), format("Result returned node id %d, expected one of %s", nodeId, Arrays.toString(ids)));
}
}
} else {
try (RelationshipValueIndexCursor cursor = ktx.cursors().allocateRelationshipValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().relationshipIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
while (cursor.next()) {
long relationshipId = cursor.relationshipReference();
assertTrue(set.remove(relationshipId), format("Result returned relationship id %d, expected one of %s", relationshipId, Arrays.toString(ids)));
}
}
}
if (!set.isEmpty()) {
fail("Number of results differ from expected. " + set.size() + " IDs were not found in the result: " + set);
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldRespectOrderCapabilitiesForNumbers.
@Test
void shouldRespectOrderCapabilitiesForNumbers() throws Exception {
// given
boolean needsValues = indexParams.indexProvidesNumericValues();
int prop = token.propertyKey(PROP_NAME);
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
IndexOrderCapability orderCapabilities = index.reference().getCapability().orderCapability(ValueCategory.NUMBER);
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
if (orderCapabilities.supportsAsc()) {
// when
entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, needsValues), PropertyIndexQuery.range(prop, 1, true, 42, true));
// then
assertFoundEntitiesInOrder(cursor, IndexOrder.ASCENDING);
}
if (orderCapabilities.supportsDesc()) {
// when
entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.DESCENDING, needsValues), PropertyIndexQuery.range(prop, 1, true, 42, true));
// then
assertFoundEntitiesInOrder(cursor, IndexOrder.DESCENDING);
}
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldPerformExactLookup.
@Test
void shouldPerformExactLookup() throws Exception {
// given
int prop = token.propertyKey(PROP_NAME);
IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(PROP_INDEX_NAME));
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
MutableLongSet uniqueIds = new LongHashSet();
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "one"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, strOne);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "two"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, strTwo1, strTwo2);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, "three"));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, strThree1, strThree2, strThree3);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 1));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 2));
// then
assertFoundEntitiesAndNoValue(cursor, 2, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 3));
// then
assertFoundEntitiesAndNoValue(cursor, 3, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 6));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, num6);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, 12.0));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, num12a, num12b);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, true));
// then
assertFoundEntitiesAndNoValue(cursor, uniqueIds, boolTrue);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(Cartesian, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 3, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(Cartesian_3D, 0, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(WGS84, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, Values.pointValue(WGS84_3D, 0, 0, 0)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, DateValue.date(1989, 3, 24)));
// then
assertFoundEntitiesAndNoValue(cursor, 2, uniqueIds);
// when
entityParams.entityIndexSeek(tx, index, cursor, unconstrained(), PropertyIndexQuery.exact(prop, DateValue.date(1986, 11, 18)));
// then
assertFoundEntitiesAndNoValue(cursor, 1, uniqueIds);
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldFindUpdatedEntityInCompositeIndex.
@Test
void shouldFindUpdatedEntityInCompositeIndex() throws Exception {
// Given
boolean needsValues = false;
int firstName = token.propertyKey(FIRSTNAME_PROP_NAME);
int surname = token.propertyKey(SURNAME_PROP_NAME);
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(COMPOSITE_INDEX_NAME));
try (KernelTransaction tx = beginTransaction();
var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
// when
entityParams.entitySetProperty(tx, jackDalton, firstName, "Jesse");
entityParams.entitySetProperty(tx, jackDalton, surname, "James");
entityParams.entityIndexSeek(tx, index, cursor, unordered(needsValues), PropertyIndexQuery.exact(firstName, "Jesse"), PropertyIndexQuery.exact(surname, "James"));
// then
assertTrue(cursor.next());
assertEquals(jackDalton, entityParams.entityReference(cursor));
}
}
Aggregations