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();
}
}
Aggregations