Search in sources :

Example 1 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class FulltextIndexProviderTest method createAndQueryFulltextRelationshipIndex.

@Test
void createAndQueryFulltextRelationshipIndex() throws Exception {
    IndexDescriptor indexReference;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe, propIdHo });
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(FULLTEXT).withName("fulltext");
        indexReference = transaction.schemaWrite().indexCreate(prototype);
        transaction.success();
    }
    await(indexReference);
    long secondRelId;
    try (Transaction transaction = db.beginTx()) {
        Relationship ho = transaction.getNodeById(node1.getId()).createRelationshipTo(transaction.getNodeById(node2.getId()), RelationshipType.withName("ho"));
        secondRelId = ho.getId();
        ho.setProperty("hej", "villa");
        ho.setProperty("ho", "value3");
        transaction.commit();
    }
    verifyRelationshipData(secondRelId);
    controller.restartDbms();
    verifyRelationshipData(secondRelId);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) 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) Relationship(org.neo4j.graphdb.Relationship) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class FulltextIndexProviderTest method createAndRetainRelationshipFulltextIndex.

@Test
void createAndRetainRelationshipFulltextIndex() throws Exception {
    IndexDescriptor indexReference;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe, propIdHo });
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(FULLTEXT).withName("fulltext");
        indexReference = transaction.schemaWrite().indexCreate(prototype);
        transaction.success();
    }
    await(indexReference);
    controller.restartDbms();
    verifyThatFulltextIndexIsPresent(indexReference);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class FulltextIndexProviderTest method validateMustThrowIfSchemaIsNotFulltext.

@Test
void validateMustThrowIfSchemaIsNotFulltext() throws Exception {
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        int[] propertyIds = { propIdHa };
        SchemaDescriptor schema = SchemaDescriptor.forLabel(labelIdHa, propertyIds);
        IndexPrototype prototype = IndexPrototype.forSchema(schema).withIndexType(FULLTEXT).withName(NAME);
        SchemaWrite schemaWrite = transaction.schemaWrite();
        var e = assertThrows(IllegalArgumentException.class, () -> schemaWrite.indexCreate(prototype));
        assertThat(e.getMessage()).contains("schema is not a full-text index schema");
        transaction.success();
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Test(org.junit.jupiter.api.Test)

Example 4 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class Database method createLookupIndex.

private void createLookupIndex(KernelTransaction tx, EntityType entityType) throws KernelException {
    var descriptor = SchemaDescriptor.forAnyEntityTokens(entityType);
    IndexPrototype prototype = IndexPrototype.forSchema(descriptor).withIndexType(LOOKUP).withIndexProvider(indexProviderMap.getTokenIndexProvider().getProviderDescriptor());
    prototype = prototype.withName(SchemaRule.generateName(prototype, new String[] {}, new String[] {}));
    tx.schemaWrite().indexCreate(prototype);
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype)

Example 5 with IndexPrototype

use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.

the class IndexProviderTests method validatePrototypeMustAcceptValidPrototype.

/* validatePrototype */
@Test
void validatePrototypeMustAcceptValidPrototype() {
    // given
    provider = newProvider();
    // when
    IndexPrototype validPrototype = validPrototype();
    // then
    assertDoesNotThrow(() -> provider.validatePrototype(validPrototype));
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Test(org.junit.jupiter.api.Test)

Aggregations

IndexPrototype (org.neo4j.internal.schema.IndexPrototype)45 Test (org.junit.jupiter.api.Test)25 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)24 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)8 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)7 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)7 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)7 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 NamedToken (org.neo4j.token.api.NamedToken)3 KernelException (org.neo4j.exceptions.KernelException)2 Transaction (org.neo4j.graphdb.Transaction)2 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)2 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)2 IndexConfig (org.neo4j.internal.schema.IndexConfig)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2