Search in sources :

Example 1 with ExtendedNodeValueIndexCursorAdapter

use of org.neo4j.kernel.impl.newapi.ExtendedNodeValueIndexCursorAdapter 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)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)1 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)1 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)1 Read (org.neo4j.internal.kernel.api.Read)1 TokenRead (org.neo4j.internal.kernel.api.TokenRead)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexProgressor (org.neo4j.kernel.api.index.IndexProgressor)1 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)1 ExtendedNodeValueIndexCursorAdapter (org.neo4j.kernel.impl.newapi.ExtendedNodeValueIndexCursorAdapter)1 Value (org.neo4j.values.storable.Value)1