Search in sources :

Example 6 with IndexDescriptor

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();
    }
}
Also used : KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 7 with IndexDescriptor

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.");
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with IndexDescriptor

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);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Label(org.neo4j.graphdb.Label) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 9 with IndexDescriptor

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.");
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 10 with IndexDescriptor

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")));
    }
}
Also used : Path(java.nio.file.Path) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)404 Test (org.junit.jupiter.api.Test)231 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)81 Value (org.neo4j.values.storable.Value)43 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)33 ArrayList (java.util.ArrayList)31 Transaction (org.neo4j.graphdb.Transaction)31 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)31 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)30 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)30 TokenRead (org.neo4j.internal.kernel.api.TokenRead)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)26 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)25 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)23 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)23 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)22 KernelException (org.neo4j.exceptions.KernelException)20