Search in sources :

Example 11 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor 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 12 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor 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 13 with IndexDescriptor

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

the class LuceneFulltextTestSupport method assertQueryFindsIds.

void assertQueryFindsIds(KernelTransaction ktx, boolean nodes, String indexName, String query, long... ids) throws Exception {
    IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
    IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
    MutableLongSet set = LongSets.mutable.of(ids);
    if (nodes) {
        try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
            while (cursor.next()) {
                long nodeId = cursor.nodeReference();
                assertTrue(set.remove(nodeId), format("Result returned node id %d, expected one of %s", nodeId, Arrays.toString(ids)));
            }
        }
    } else {
        try (RelationshipValueIndexCursor cursor = ktx.cursors().allocateRelationshipValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            ktx.dataRead().relationshipIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
            while (cursor.next()) {
                long relationshipId = cursor.relationshipReference();
                assertTrue(set.remove(relationshipId), format("Result returned relationship id %d, expected one of %s", relationshipId, Arrays.toString(ids)));
            }
        }
    }
    if (!set.isEmpty()) {
        fail("Number of results differ from expected. " + set.size() + " IDs were not found in the result: " + set);
    }
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 14 with IndexDescriptor

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

the class SchemaStorageIT method shouldReturnIndexRuleForLabelAndPropertyComposite.

@Test
void shouldReturnIndexRuleForLabelAndPropertyComposite() {
    String a = "a";
    String b = "b";
    String c = "c";
    String d = "d";
    String e = "e";
    String f = "f";
    createSchema(tx -> tx.schema().indexFor(Label.label(LABEL1)).on(a).on(b).on(c).on(d).on(e).on(f).create());
    IndexDescriptor rule = single(storage.indexGetForSchema(TestIndexDescriptorFactory.forLabel(labelId(LABEL1), propId(a), propId(b), propId(c), propId(d), propId(e), propId(f)), NULL));
    assertNotNull(rule);
    assertTrue(SchemaDescriptorPredicates.hasLabel(rule, labelId(LABEL1)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(a)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(b)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(c)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(d)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(e)));
    assertTrue(SchemaDescriptorPredicates.hasProperty(rule, propId(f)));
    assertFalse(rule.isUnique());
}
Also used : IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 15 with IndexDescriptor

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

the class SchemaStorageIT method shouldReturnIndexRuleForLabelAndProperty.

@Test
void shouldReturnIndexRuleForLabelAndProperty() {
    // Given
    createSchema(index(LABEL1, PROP1), index(LABEL1, PROP2), index(LABEL2, PROP1));
    // When
    IndexDescriptor rule = single(storage.indexGetForSchema(indexDescriptor(LABEL1, PROP2), NULL));
    // Then
    assertNotNull(rule);
    assertRule(rule, LABEL1, PROP2, false);
}
Also used : 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