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);
}
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);
}
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);
}
}
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());
}
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);
}
Aggregations