use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexProvidedValuesNativeBTree10Test method shouldGetAllDoublePropertyValues.
@Test
void shouldGetAllDoublePropertyValues() throws Exception {
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_PRIP_INDEX));
var values = getEntityControl().findValuePairs(tx, cursors, index);
assertThat(values).as("index should return all double property values").containsExactlyInAnyOrderElementsOf(doublePropValues);
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexProvidedValuesNativeBTree10Test method shouldGetAllSinglePropertyValues.
@Test
void shouldGetAllSinglePropertyValues() throws Exception {
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX));
var values = getEntityControl().findValues(tx, cursors, index);
assertThat(values).as("index should return all single property values").containsExactlyInAnyOrderElementsOf(singlePropValues);
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class KernelReadTracerTxStateTest method shouldTraceRelationshipIndexCursor.
@Test
void shouldTraceRelationshipIndexCursor() throws KernelException, TimeoutException {
// given
int connection;
int name;
String indexName = "myIndex";
IndexDescriptor index;
try (KernelTransaction tx = beginTransaction()) {
connection = tx.tokenWrite().relationshipTypeGetOrCreateForName("Connection");
name = tx.tokenWrite().propertyKeyGetOrCreateForName("name");
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, array(connection), array(name));
IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withName(indexName).withIndexType(IndexType.FULLTEXT);
index = tx.schemaWrite().indexCreate(prototype);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
Predicates.awaitEx(() -> tx.schemaRead().indexGetState(index) == ONLINE, 1, MINUTES);
long n1 = tx.dataWrite().nodeCreate();
long n2 = tx.dataWrite().nodeCreate();
long r = tx.dataWrite().relationshipCreate(n1, connection, n2);
tx.dataWrite().relationshipSetProperty(r, name, Values.stringValue("transformational"));
tx.commit();
}
// when
TestKernelReadTracer tracer = new TestKernelReadTracer();
try (KernelTransaction tx = beginTransaction();
RelationshipValueIndexCursor cursor = tx.cursors().allocateRelationshipValueIndexCursor(NULL, tx.memoryTracker())) {
cursor.setTracer(tracer);
IndexReadSession indexReadSession = tx.dataRead().indexReadSession(index);
tx.dataRead().relationshipIndexSeek(indexReadSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch("transformational"));
assertTrue(cursor.next());
tracer.assertEvents(OnIndexSeek(), OnRelationship(cursor.relationshipReference()));
assertFalse(cursor.next());
tracer.assertEvents();
}
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class FulltextProcedures method queryFulltextForRelationships.
@SystemProcedure
@Description("Query the given full-text index. Returns the matching relationships, and their Lucene query score, ordered by score. " + "Valid keys for the options map are: 'skip' to skip the top N results; 'limit' to limit the number of results returned.")
@Procedure(name = "db.index.fulltext.queryRelationships", mode = READ)
public Stream<RelationshipOutput> queryFulltextForRelationships(@Name("indexName") String name, @Name("queryString") String query, @Name(value = "options", defaultValue = "{}") Map<String, Object> options) throws Exception {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
IndexDescriptor indexReference = getValidIndex(name);
awaitOnline(indexReference);
EntityType entityType = indexReference.schema().entityType();
if (entityType != RELATIONSHIP) {
throw new IllegalArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for relationships.");
}
RelationshipValueIndexCursor cursor = tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
IndexReadSession indexReadSession = tx.dataRead().indexReadSession(indexReference);
IndexQueryConstraints constraints = queryConstraints(options);
tx.dataRead().relationshipIndexSeek(indexReadSession, cursor, constraints, PropertyIndexQuery.fulltextSearch(query));
Spliterator<RelationshipOutput> spliterator = new SpliteratorAdaptor<>() {
@Override
public boolean tryAdvance(Consumer<? super RelationshipOutput> action) {
while (cursor.next()) {
long relationshipReference = cursor.relationshipReference();
float score = cursor.score();
RelationshipOutput relationshipOutput = RelationshipOutput.forExistingEntityOrNull(transaction, relationshipReference, score);
if (relationshipOutput != null) {
action.accept(relationshipOutput);
return true;
}
}
cursor.close();
return false;
}
};
return StreamSupport.stream(spliterator, false).onClose(cursor::close);
}
use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.
the class IndexStatisticsTest method assertIndexedNodesMatchesStoreNodes.
private void assertIndexedNodesMatchesStoreNodes(IndexDescriptor index) throws Exception {
int nodesInStore = 0;
Label label = Label.label(PERSON_LABEL);
try (Transaction transaction = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) transaction).kernelTransaction();
List<String> mismatches = new ArrayList<>();
int propertyKeyId = ktx.tokenRead().propertyKey(NAME_PROPERTY);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
// Node --> Index
for (Node node : filter(n -> n.hasLabel(label) && n.hasProperty(NAME_PROPERTY), transaction.getAllNodes())) {
nodesInStore++;
String name = (String) node.getProperty(NAME_PROPERTY);
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, name));
boolean found = false;
while (cursor.next()) {
long indexedNode = cursor.nodeReference();
if (indexedNode == node.getId()) {
if (found) {
mismatches.add("Index has multiple entries for " + name + " and " + indexedNode);
}
found = true;
}
}
if (!found) {
mismatches.add("Index is missing entry for " + name + " " + node);
}
}
if (!mismatches.isEmpty()) {
fail(String.join(format("%n"), mismatches));
}
// Node count == indexed node count
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exists(propertyKeyId));
int nodesInIndex = 0;
while (cursor.next()) {
nodesInIndex++;
}
assertEquals(nodesInStore, nodesInIndex);
}
}
}
Aggregations