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