Search in sources :

Example 6 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class FulltextProcedures method createRelationshipFulltextIndex.

@Deprecated(since = "4.3.0", forRemoval = true)
@Description("Create a relationship full-text index for the given relationship types and properties. " + "The optional 'config' map parameter can be used to supply settings to the index. " + "Supported settings are '" + PROCEDURE_ANALYZER + "', for specifying what analyzer to use " + "when indexing and querying. Use the `db.index.fulltext.listAvailableAnalyzers` procedure to see what options are available. " + "And '" + PROCEDURE_EVENTUALLY_CONSISTENT + "' which can be set to 'true' to make this index eventually consistent, " + "such that updates from committing transactions are applied in a background thread.")
@Procedure(name = "db.index.fulltext.createRelationshipIndex", mode = SCHEMA, deprecatedBy = "CREATE FULLTEXT INDEX command")
public void createRelationshipFulltextIndex(@Name("indexName") String name, @Name("relationshipTypes") List<String> relTypes, @Name("properties") List<String> properties, @Name(value = "config", defaultValue = "{}") Map<String, String> config) {
    RelationshipType[] types = relTypes.stream().map(RelationshipType::withName).toArray(RelationshipType[]::new);
    IndexCreator indexCreator = transaction.schema().indexFor(types);
    createIndex(indexCreator, name, properties, config);
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 7 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class FulltextProcedures method createNodeFulltextIndex.

@Deprecated(since = "4.3.0", forRemoval = true)
@Description("Create a node full-text index for the given labels and properties. " + "The optional 'config' map parameter can be used to supply settings to the index. " + "Supported settings are '" + PROCEDURE_ANALYZER + "', for specifying what analyzer to use " + "when indexing and querying. Use the `db.index.fulltext.listAvailableAnalyzers` procedure to see what options are available. " + "And '" + PROCEDURE_EVENTUALLY_CONSISTENT + "' which can be set to 'true' to make this index eventually consistent, " + "such that updates from committing transactions are applied in a background thread.")
@Procedure(name = "db.index.fulltext.createNodeIndex", mode = SCHEMA, deprecatedBy = "CREATE FULLTEXT INDEX command")
public void createNodeFulltextIndex(@Name("indexName") String name, @Name("labels") List<String> labelNames, @Name("properties") List<String> properties, @Name(value = "config", defaultValue = "{}") Map<String, String> config) {
    Label[] labels = labelNames.stream().map(Label::label).toArray(Label[]::new);
    IndexCreator indexCreator = transaction.schema().indexFor(labels);
    createIndex(indexCreator, name, properties, config);
}
Also used : Label(org.neo4j.graphdb.Label) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 8 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class SchemaAcceptanceTest method indexSettingsWithNonsensicalValuesMustBeRejected.

@Test
void indexSettingsWithNonsensicalValuesMustBeRejected() {
    try (Transaction tx = db.beginTx()) {
        Exception e;
        IndexCreator creator = tx.schema().indexFor(label).withName("my_index").on(propertyKey);
        e = assertThrows(IllegalArgumentException.class, () -> creator.withIndexType(IndexType.FULLTEXT).withIndexConfiguration(Map.of(IndexSettingImpl.FULLTEXT_ANALYZER, "analyzer that does not exist")).create());
        assertThat(e).hasMessageContaining("'analyzer that does not exist'");
        e = assertThrows(IllegalArgumentException.class, () -> creator.withIndexConfiguration(Map.of(IndexSettingImpl.SPATIAL_CARTESIAN_MAX, new double[] { 100.0, 10.0, 1.0 })).create());
        assertThat(e).hasMessageContaining("Invalid spatial index settings");
        tx.commit();
    }
}
Also used : IndexCreator(org.neo4j.graphdb.schema.IndexCreator) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IndexWithNameAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.IndexWithNameAlreadyExistsException) ConstraintWithNameAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.ConstraintWithNameAlreadyExistsException) NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) EquivalentSchemaRuleAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.EquivalentSchemaRuleAlreadyExistsException) AlreadyIndexedException(org.neo4j.kernel.api.exceptions.schema.AlreadyIndexedException) ExecutionException(java.util.concurrent.ExecutionException) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class SchemaAcceptanceTest method createIndexNoWait.

static IndexDefinition createIndexNoWait(GraphDatabaseService db, String name, Label label, String... properties) {
    IndexDefinition indexDef;
    try (Transaction tx = db.beginTx()) {
        IndexCreator indexCreator = tx.schema().indexFor(label);
        for (String property : properties) {
            indexCreator = indexCreator.on(property);
        }
        if (name != null) {
            indexCreator = indexCreator.withName(name);
        }
        indexDef = indexCreator.create();
        tx.commit();
    }
    return indexDef;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexCreator(org.neo4j.graphdb.schema.IndexCreator)

Example 10 with IndexCreator

use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.

the class SchemaAcceptanceTest method mustCreateFullTextIndexBySettingIndexType.

@Test
void mustCreateFullTextIndexBySettingIndexType() {
    try (Transaction tx = db.beginTx()) {
        IndexCreator creator = tx.schema().indexFor(label).on(propertyKey).withIndexType(IndexType.FULLTEXT);
        IndexDefinition definition = creator.create();
        assertEquals(IndexType.FULLTEXT, definition.getIndexType());
        IndexProviderDescriptor provider = ((IndexDefinitionImpl) definition).getIndexReference().getIndexProvider();
        assertEquals(provider, FulltextIndexProviderFactory.DESCRIPTOR);
        tx.commit();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IndexCreator (org.neo4j.graphdb.schema.IndexCreator)29 Test (org.junit.jupiter.api.Test)17 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Transaction (org.neo4j.graphdb.Transaction)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)5 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)5 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)4 Schema (org.neo4j.graphdb.schema.Schema)4 Label (org.neo4j.graphdb.Label)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 Description (org.neo4j.procedure.Description)2 Procedure (org.neo4j.procedure.Procedure)2 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1