public override SchemaDescriptor SchemaFor(EntityType type, string[] entityTokens, Properties indexConfiguration, params string[] properties)
        {
            if (entityTokens.Length == 0)
            {
                throw new BadSchemaException("At least one " + (type == EntityType.NODE ? "label" : "relationship type") + " must be specified when creating a fulltext index.");
            }
            if (properties.Length == 0)
            {
                throw new BadSchemaException("At least one property name must be specified when creating a fulltext index.");
            }
            if (Arrays.asList(properties).contains(LuceneFulltextDocumentStructure.FIELD_ENTITY_ID))
            {
                throw new BadSchemaException("Unable to index the property, the name is reserved for internal use " + LuceneFulltextDocumentStructure.FIELD_ENTITY_ID);
            }
            int[] entityTokenIds = new int[entityTokens.Length];
            if (type == EntityType.NODE)
            {
                _tokenHolders.labelTokens().getOrCreateIds(entityTokens, entityTokenIds);
            }
            else
            {
                _tokenHolders.relationshipTypeTokens().getOrCreateIds(entityTokens, entityTokenIds);
            }
            int[] propertyIds = java.util.properties.Select(_tokenHolders.propertyKeyTokens().getOrCreateId).ToArray();

            SchemaDescriptor schema = SchemaDescriptorFactory.multiToken(entityTokenIds, type, propertyIds);

            indexConfiguration.putIfAbsent(FulltextIndexSettings.INDEX_CONFIG_ANALYZER, _defaultAnalyzerName);
            indexConfiguration.putIfAbsent(FulltextIndexSettings.INDEX_CONFIG_EVENTUALLY_CONSISTENT, _defaultEventuallyConsistentSetting);
            return(new FulltextSchemaDescriptor(schema, indexConfiguration));
        }
Beispiel #2
0
        private SchemaDescriptor RandomSchemaDescriptor(int highEntityKeyId, int highPropertyKeyId, int maxNumberOfEntityKeys, int maxNumberOfPropertyKeys)
        {
            int numberOfEntityKeys = _random.Next(1, maxNumberOfEntityKeys);

            int[] entityKeys           = RandomUniqueUnsortedIntArray(highEntityKeyId, numberOfEntityKeys);
            int   numberOfPropertyKeys = _random.Next(1, maxNumberOfPropertyKeys);

            int[] propertyKeys = RandomUniqueUnsortedIntArray(highPropertyKeyId, numberOfPropertyKeys);
            return(entityKeys.Length > 1 ? SchemaDescriptorFactory.multiToken(entityKeys, EntityType.NODE, propertyKeys) : SchemaDescriptorFactory.forLabel(entityKeys[0], propertyKeys));
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListMultiTokenIndexesInTheCoreAPI() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldListMultiTokenIndexesInTheCoreAPI()
        {
            Transaction transaction = NewTransaction(AUTH_DISABLED);
            MultiTokenSchemaDescriptor descriptor = SchemaDescriptorFactory.multiToken(new int[] { _labelId, _labelId2 }, EntityType.NODE, _propertyKeyId);

            transaction.SchemaWrite().indexCreate(descriptor);
            Commit();

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: try (@SuppressWarnings("unused") org.neo4j.graphdb.Transaction tx = db.beginTx())
            using (Org.Neo4j.Graphdb.Transaction tx = Db.beginTx())
            {
                ISet <IndexDefinition> indexes = Iterables.asSet(Db.schema().Indexes);

                // then
                assertEquals(1, indexes.Count);
                IndexDefinition index = indexes.GetEnumerator().next();
                try
                {
                    index.Label;
                    fail("index.getLabel() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                try
                {
                    index.RelationshipType;
                    fail("index.getRelationshipType() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                try
                {
                    index.RelationshipTypes;
                    fail("index.getRelationshipTypes() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                assertThat(index.Labels, containsInAnyOrder(label(LABEL), label(LABEL2)));
                assertFalse("should not be a constraint index", index.ConstraintIndex);
                assertTrue("should be a multi-token index", index.MultiTokenIndex);
                assertFalse("should not be a composite index", index.CompositeIndex);
                assertTrue("should be a node index", index.NodeIndex);
                assertFalse("should not be a relationship index", index.RelationshipIndex);
                assertEquals(asSet(PROPERTY_KEY), Iterables.asSet(index.PropertyKeys));
            }
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListCompositeMultiTokenRelationshipIndexesInTheCoreAPI() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldListCompositeMultiTokenRelationshipIndexesInTheCoreAPI()
        {
            Transaction      transaction = NewTransaction(AUTH_DISABLED);
            SchemaDescriptor descriptor  = SchemaDescriptorFactory.multiToken(new int[] { _relType, _relType2 }, EntityType.RELATIONSHIP, _propertyKeyId, _propertyKeyId2);

            transaction.SchemaWrite().indexCreate(descriptor);
            Commit();

            using (Org.Neo4j.Graphdb.Transaction tx = Db.beginTx())
            {
                ISet <IndexDefinition> indexes = Iterables.asSet(Db.schema().Indexes);

                // then
                assertEquals(1, indexes.Count);
                IndexDefinition index = indexes.GetEnumerator().next();
                try
                {
                    index.Label;
                    fail("index.getLabel() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                try
                {
                    index.Labels;
                    fail("index.getLabels() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                try
                {
                    index.RelationshipType;
                    fail("index.getRelationshipType() should have thrown. ");
                }
                catch (System.InvalidOperationException)
                {
                }
                assertThat(index.RelationshipTypes, containsInAnyOrder(withName(REL_TYPE), withName(REL_TYPE2)));
                assertFalse("should not be a constraint index", index.ConstraintIndex);
                assertTrue("should be a multi-token index", index.MultiTokenIndex);
                assertTrue("should be a composite index", index.CompositeIndex);
                assertFalse("should not be a node index", index.NodeIndex);
                assertTrue("should be a relationship index", index.RelationshipIndex);
                assertEquals(asSet(PROPERTY_KEY, PROPERTY_KEY2), Iterables.asSet(index.PropertyKeys));
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @MethodSource("nodeAndRelationshipEntityTypes") void shouldMatchOnAnyEntityAndPropertyTokenForPartialPropertySchemaType(org.neo4j.storageengine.api.EntityType entityType)
        internal virtual void ShouldMatchOnAnyEntityAndPropertyTokenForPartialPropertySchemaType(EntityType entityType)
        {
            // given
            SchemaDescriptorLookupSet <SchemaDescriptor> set = new SchemaDescriptorLookupSet <SchemaDescriptor>();
            MultiTokenSchemaDescriptor descriptor1           = SchemaDescriptorFactory.multiToken(Ints(0, 1, 2), entityType, 3, 4, 5);
            MultiTokenSchemaDescriptor descriptor2           = SchemaDescriptorFactory.multiToken(Ints(0, 1), entityType, 3, 4);
            MultiTokenSchemaDescriptor descriptor3           = SchemaDescriptorFactory.multiToken(Ints(0, 2), entityType, 4, 5);

            set.Add(descriptor1);
            set.Add(descriptor2);
            set.Add(descriptor3);

            // given that this test revolves around entity tokens 0,1,2 and property tokens 3,4,5 these 3 descriptors below matches either
            // only those tokens for entity or property or neither. I.e. these should never be included in matching results
            set.Add(SchemaDescriptorFactory.multiToken(Ints(3, 4), entityType, 4, 5));
            set.Add(SchemaDescriptorFactory.multiToken(Ints(0, 1), entityType, 6, 7));
            set.Add(SchemaDescriptorFactory.multiToken(Ints(3, 4), entityType, 6, 7));

            // when matching these descriptors (in this case partial/complete list doesn't quite matter because the descriptors
            // themselves are partially matched anyway.
            ISet <SchemaDescriptor> descriptors1        = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors1Partial = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors2        = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors2Partial = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors3        = new HashSet <SchemaDescriptor>();
            ISet <SchemaDescriptor> descriptors3Partial = new HashSet <SchemaDescriptor>();

            set.MatchingDescriptorsForCompleteListOfProperties(descriptors1, Longs(0, 1), Ints(4, 5));
            set.MatchingDescriptorsForPartialListOfProperties(descriptors1Partial, Longs(0, 1), Ints(4, 5));
            set.MatchingDescriptorsForCompleteListOfProperties(descriptors2, Longs(0), Ints(3));
            set.MatchingDescriptorsForPartialListOfProperties(descriptors2Partial, Longs(0), Ints(3));
            set.MatchingDescriptorsForCompleteListOfProperties(descriptors3, Longs(1), Ints(5));
            set.MatchingDescriptorsForPartialListOfProperties(descriptors3Partial, Longs(1), Ints(5));

            // then
            assertEquals(asSet(descriptor1, descriptor2, descriptor3), descriptors1);
            assertEquals(asSet(descriptor1, descriptor2, descriptor3), descriptors1Partial);
            assertEquals(asSet(descriptor1, descriptor2), descriptors2);
            assertEquals(asSet(descriptor1, descriptor2), descriptors2Partial);
            assertEquals(asSet(descriptor1), descriptors3);
            assertEquals(asSet(descriptor1), descriptors3Partial);
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void removeSchemaWithRepeatedRelType()
        public virtual void RemoveSchemaWithRepeatedRelType()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SchemaCache cache = newSchemaCache();
            SchemaCache cache = NewSchemaCache();

            const int id = 1;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int[] repeatedRelTypes = {0, 1, 0};
            int[] repeatedRelTypes = new int[] { 0, 1, 0 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.api.schema.MultiTokenSchemaDescriptor schema = org.neo4j.kernel.api.schema.SchemaDescriptorFactory.multiToken(repeatedRelTypes, org.neo4j.storageengine.api.EntityType.RELATIONSHIP, 1);
            MultiTokenSchemaDescriptor schema = SchemaDescriptorFactory.multiToken(repeatedRelTypes, EntityType.RELATIONSHIP, 1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.schema.StoreIndexDescriptor storeIndexDescriptor = org.neo4j.storageengine.api.schema.IndexDescriptorFactory.forSchema(schema).withId(id);
            StoreIndexDescriptor storeIndexDescriptor = IndexDescriptorFactory.forSchema(schema).withId(id);

            cache.AddSchemaRule(storeIndexDescriptor);
            cache.RemoveSchemaRule(id);
        }