Search in sources :

Example 71 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class FulltextIndexProviderTest method assertQueryResult.

private void assertQueryResult(KernelTransaction ktx, PropertyIndexQuery query, Long... expectedResultArray) throws KernelException {
    List<Long> expectedResult = Arrays.asList(expectedResultArray);
    IndexReadSession index = ktx.dataRead().indexReadSession(ktx.schemaRead().indexGetForName(NAME));
    try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
        List<Long> actualResult = new ArrayList<>();
        ktx.dataRead().nodeIndexSeek(index, cursor, unconstrained(), query);
        while (cursor.next()) {
            actualResult.add(cursor.nodeReference());
        }
        actualResult.sort(Long::compareTo);
        expectedResult.sort(Long::compareTo);
        assertThat(actualResult).isEqualTo(expectedResult);
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 72 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class FulltextIndexProviderTest method queryingWithIndexProgressorMustProvideScore.

@Test
void queryingWithIndexProgressorMustProvideScore() throws Exception {
    long nodeId = createTheThirdNode();
    IndexDescriptor index;
    index = createIndex(new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe, propIdHo });
    await(index);
    List<String> acceptedEntities = new ArrayList<>();
    try (KernelTransactionImplementation ktx = getKernelTransaction()) {
        NodeValueIndexCursor cursor = new ExtendedNodeValueIndexCursorAdapter() {

            private long nodeReference;

            private IndexProgressor progressor;

            @Override
            public long nodeReference() {
                return nodeReference;
            }

            @Override
            public boolean next() {
                return progressor.next();
            }

            @Override
            public void initialize(IndexDescriptor descriptor, IndexProgressor progressor, PropertyIndexQuery[] query, IndexQueryConstraints constraints, boolean indexIncludesTransactionState) {
                this.progressor = progressor;
            }

            @Override
            public boolean acceptEntity(long reference, float score, Value... values) {
                this.nodeReference = reference;
                assertFalse(Float.isNaN(score), "score should not be NaN");
                assertThat(score).as("score must be positive").isGreaterThan(0.0f);
                acceptedEntities.add("reference = " + reference + ", score = " + score + ", " + Arrays.toString(values));
                return true;
            }
        };
        Read read = ktx.dataRead();
        IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
        read.nodeIndexSeek(indexSession, cursor, unconstrained(), fulltextSearch("hej:\"villa\""));
        int counter = 0;
        while (cursor.next()) {
            assertThat(cursor.nodeReference()).isEqualTo(nodeId);
            counter++;
        }
        assertThat(counter).isEqualTo(1);
        assertThat(acceptedEntities.size()).isEqualTo(1);
        acceptedEntities.clear();
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) ExtendedNodeValueIndexCursorAdapter(org.neo4j.kernel.impl.newapi.ExtendedNodeValueIndexCursorAdapter) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) Value(org.neo4j.values.storable.Value) Test(org.junit.jupiter.api.Test)

Example 73 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class FulltextIndexProviderTest method verifyRelationshipData.

private void verifyRelationshipData(long secondRelId) throws Exception {
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        IndexDescriptor index = ktx.schemaRead().indexGetForName("fulltext");
        IndexReadSession indexReadSession = ktx.dataRead().indexReadSession(index);
        try (RelationshipValueIndexCursor cursor = ktx.cursors().allocateRelationshipValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            ktx.dataRead().relationshipIndexSeek(indexReadSession, cursor, unconstrained(), fulltextSearch("valuuu"));
            assertTrue(cursor.next());
            assertEquals(0L, cursor.relationshipReference());
            assertFalse(cursor.next());
            ktx.dataRead().relationshipIndexSeek(indexReadSession, cursor, unconstrained(), fulltextSearch("villa"));
            assertTrue(cursor.next());
            assertEquals(secondRelId, cursor.relationshipReference());
            assertFalse(cursor.next());
            ktx.dataRead().relationshipIndexSeek(indexReadSession, cursor, unconstrained(), fulltextSearch("value3"));
            assertTrue(cursor.next());
            assertEquals(0L, cursor.relationshipReference());
            assertTrue(cursor.next());
            assertEquals(secondRelId, cursor.relationshipReference());
            assertFalse(cursor.next());
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 74 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldPerformBooleanSearch.

@Test
void shouldPerformBooleanSearch() throws KernelException {
    // given
    boolean needsValues = indexParams.indexProvidesBooleanValues();
    IndexQueryConstraints constraints = unordered(needsValues);
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability capability = index.reference().getCapability().valueCapability(ValueGroup.BOOLEAN.category());
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, false));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, true));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 75 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldNotFindDeletedEntityInRangeSearch.

@Test
void shouldNotFindDeletedEntityInRangeSearch() throws Exception {
    // Given
    boolean needsValues = indexParams.indexProvidesStringValues();
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    try (KernelTransaction tx = beginTransaction();
        var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        // when
        entityParams.entityDelete(tx, strOne);
        entityParams.entityDelete(tx, strThree1);
        entityParams.entityDelete(tx, strThree2);
        entityParams.entityDelete(tx, strThree3);
        entityParams.entityIndexSeek(tx, index, cursor, unordered(needsValues), PropertyIndexQuery.range(prop, "one", true, "three", true));
        // then
        assertFalse(cursor.next());
    }
}
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