use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class FulltextIndexProviderTest method createFulltextIndex.
@Test
void createFulltextIndex() throws Exception {
IndexDescriptor fulltextIndex = createIndex(new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe });
try (KernelTransactionImplementation transaction = getKernelTransaction()) {
IndexDescriptor descriptor = transaction.schemaRead().indexGetForName(NAME);
assertEquals(descriptor.schema(), fulltextIndex.schema());
transaction.success();
}
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldThrowOnCypherFulltextQueryIfNotCypherCompatibleMultipleEntities.
@Test
void shouldThrowOnCypherFulltextQueryIfNotCypherCompatibleMultipleEntities() throws KernelException {
IndexDescriptor indexReference = createIndex(new int[] { labelIdHa, labelIdHe }, new int[] { propIdHa }, "cypher");
await(indexReference);
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
IllegalStateException e = assertThrows(IllegalStateException.class, () -> assertQueryResult(ktx, endsWithQuery(1, "a")));
assertThat(e.getMessage()).contains("This fulltext index does not have support for Cypher semantics because index target more than one label.");
}
}
use of org.neo4j.internal.schema.IndexDescriptor 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.schema.IndexDescriptor in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldThrowOnCypherFulltextQueryIfNotCypherCompatibleComposite.
@Test
void shouldThrowOnCypherFulltextQueryIfNotCypherCompatibleComposite() throws KernelException {
IndexDescriptor indexReference = createIndex(new int[] { labelIdHa }, new int[] { propIdHa, propIdHe }, "cypher");
await(indexReference);
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
IllegalStateException e = assertThrows(IllegalStateException.class, () -> assertQueryResult(ktx, endsWithQuery(1, "a")));
assertThat(e.getMessage()).contains("This fulltext index does not have support for Cypher semantics because index is composite.");
}
}
use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.
the class FulltextIndexProviderTest method shouldHaveAReasonableDirectoryStructure.
@Test
void shouldHaveAReasonableDirectoryStructure() throws Exception {
createIndex(new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe });
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(1, TimeUnit.HOURS);
tx.commit();
}
try (KernelTransactionImplementation transaction = getKernelTransaction()) {
IndexDescriptor descriptor = transaction.schemaRead().indexGetForName(NAME);
Path indexDir = Path.of(db.databaseLayout().databaseDirectory().toAbsolutePath().toString(), "schema", "index", descriptor.getIndexProvider().name(), "" + descriptor.getId());
List<Path> listFiles = List.of(requireNonNull(FileUtils.listPaths(indexDir)));
assertTrue(listFiles.contains(indexDir.resolve("failure-message")));
assertTrue(listFiles.contains(indexDir.resolve("1")));
assertTrue(listFiles.contains(indexDir.resolve(indexDir.getFileName() + ".tx")));
}
}
Aggregations