use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldAnswerStartsWithIfCypherCompatible.
@Test
void shouldAnswerStartsWithIfCypherCompatible() throws KernelException {
IndexDescriptor indexReference;
Label containsLabel = label("containsLabel");
String containsProp = "containsProp";
long nodea;
long nodeapa1;
long nodeapa2;
long nodeapaapa;
long nodeapalong;
try (Transaction tx = db.beginTx()) {
nodea = createNode(tx, containsLabel, containsProp, "a");
createNode(tx, containsLabel, containsProp, "A");
nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
createNode(tx, containsLabel, containsProp, "longapa");
nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
nodeapalong = createNode(tx, containsLabel, containsProp, "apalong");
tx.commit();
}
int containsLabelId;
int containsPropertyId;
try (Transaction tx = db.beginTx()) {
TokenRead tokenRead = tokenRead(tx);
containsLabelId = tokenRead.nodeLabel(containsLabel.name());
containsPropertyId = tokenRead.propertyKey(containsProp);
}
indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
await(indexReference);
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapaapa, nodeapalong);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa a"), nodeapaapa);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "*apa"));
}
controller.restartDbms();
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapaapa, nodeapalong);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa a"), nodeapaapa);
assertQueryResult(ktx, startsWithQuery(containsPropertyId, "*apa"));
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldAnswerContainsIfCypherCompatible.
@Test
void shouldAnswerContainsIfCypherCompatible() throws KernelException {
IndexDescriptor indexReference;
Label containsLabel = label("containsLabel");
String containsProp = "containsProp";
long nodea;
long nodeapa1;
long nodeapa2;
long nodeapalong;
long nodeapaapa;
try (Transaction tx = db.beginTx()) {
nodea = createNode(tx, containsLabel, containsProp, "a");
createNode(tx, containsLabel, containsProp, "A");
nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
nodeapalong = createNode(tx, containsLabel, containsProp, "apalong");
nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
tx.commit();
}
int containsLabelId;
int containsPropertyId;
try (Transaction tx = db.beginTx()) {
TokenRead tokenRead = tokenRead(tx);
containsLabelId = tokenRead.nodeLabel(containsLabel.name());
containsPropertyId = tokenRead.propertyKey(containsProp);
}
indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
await(indexReference);
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, containsQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
assertQueryResult(ktx, containsQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
assertQueryResult(ktx, containsQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, containsQuery(containsPropertyId, "pa ap"), nodeapaapa);
}
controller.restartDbms();
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
assertQueryResult(ktx, containsQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
assertQueryResult(ktx, containsQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
assertQueryResult(ktx, containsQuery(containsPropertyId, "apa*"));
assertQueryResult(ktx, containsQuery(containsPropertyId, "pa ap"), nodeapaapa);
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method verifyExpectedProvider.
private static void verifyExpectedProvider(GraphDatabaseAPI db, Label label, IndexProviderDescriptor expectedDescriptor) throws TransactionFailureException {
try (InternalTransaction tx = (InternalTransaction) db.beginTx();
KernelTransaction kernelTransaction = tx.kernelTransaction()) {
TokenRead tokenRead = kernelTransaction.tokenRead();
SchemaRead schemaRead = kernelTransaction.schemaRead();
int labelId = tokenRead.nodeLabel(label.name());
int key1Id = tokenRead.propertyKey(KEY1);
int key2Id = tokenRead.propertyKey(KEY2);
IndexDescriptor index = single(schemaRead.index(SchemaDescriptor.forLabel(labelId, key1Id)));
assertIndexHasExpectedProvider(expectedDescriptor, index);
index = single(schemaRead.index(SchemaDescriptor.forLabel(labelId, key1Id, key2Id)));
assertIndexHasExpectedProvider(expectedDescriptor, index);
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex.
@Test
void schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
ConstraintDescriptor constraint = indexBackedConstraint(index);
index = indexBoundToConstraint(index, constraint);
InternalIndexState internalIndexState = InternalIndexState.FAILED;
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(0, result.size());
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeOrphanedIndexes.
@Test
void schemaStatementsMustNotIncludeOrphanedIndexes() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
InternalIndexState indexState = InternalIndexState.ONLINE;
SchemaReadCore schemaReadCore = getSchemaReadCore(index, indexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(0, result.size());
}
Aggregations