Search in sources :

Example 1 with IndexReadSession

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);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 2 with IndexReadSession

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);
    }
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 3 with IndexReadSession

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);
        }
    }
}
Also used : IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 4 with IndexReadSession

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);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 5 with IndexReadSession

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));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Aggregations

IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)93 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)47 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)20 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)17 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)15 ArrayList (java.util.ArrayList)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)12 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)12 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)12 Pair (org.neo4j.internal.helpers.collection.Pair)11 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)10 Transaction (org.neo4j.graphdb.Transaction)9 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)9 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)7 Read (org.neo4j.internal.kernel.api.Read)6 TokenRead (org.neo4j.internal.kernel.api.TokenRead)6 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)5