//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldPersistFulltextIndexSettings() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldPersistFulltextIndexSettings()
        {
            // Given
            File   indexFolder           = Directory.directory("indexFolder");
            string analyzerName          = "simple";
            string eventuallyConsistency = "true";
            string defaultAnalyzer       = "defaultAnalyzer";

            int[] propertyIds = new int[] { 1, 2, 3 };
            MultiTokenSchemaDescriptor schema = SchemaDescriptorFactory.multiToken(new int[] { 1, 2 }, EntityType.NODE, propertyIds);

            // A fulltext index descriptor with configurations
            Properties properties = properties(analyzerName, eventuallyConsistency);
            FulltextSchemaDescriptor fulltextSchemaDescriptor = new FulltextSchemaDescriptor(schema, properties);
            StoreIndexDescriptor     storeIndexDescriptor     = StoreIndexDescriptorFromSchema(fulltextSchemaDescriptor);
            TokenRegistry            tokenRegistry            = SimpleTokenHolder.CreatePopulatedTokenRegistry(Org.Neo4j.Kernel.impl.core.TokenHolder_Fields.TYPE_PROPERTY_KEY, propertyIds);
            SimpleTokenHolder        tokenHolder             = new SimpleTokenHolder(tokenRegistry);
            FulltextIndexDescriptor  fulltextIndexDescriptor = readOrInitialiseDescriptor(storeIndexDescriptor, defaultAnalyzer, tokenHolder, indexFolder, Fs);

            assertEquals(analyzerName, fulltextIndexDescriptor.AnalyzerName());
            assertEquals(bool.Parse(eventuallyConsistency), fulltextIndexDescriptor.EventuallyConsistent);

            // When persisting it
            FulltextIndexSettings.SaveFulltextIndexSettings(fulltextIndexDescriptor, indexFolder, Fs);

            // Then we should be able to load it back with settings being the same
            StoreIndexDescriptor    loadingIndexDescriptor = StoreIndexDescriptorFromSchema(schema);
            FulltextIndexDescriptor loadedDescriptor       = readOrInitialiseDescriptor(loadingIndexDescriptor, defaultAnalyzer, tokenHolder, indexFolder, Fs);

            assertEquals(fulltextIndexDescriptor.AnalyzerName(), loadedDescriptor.AnalyzerName());
            assertEquals(fulltextIndexDescriptor.EventuallyConsistent, loadedDescriptor.EventuallyConsistent);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void createAndQueryFulltextRelationshipIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CreateAndQueryFulltextRelationshipIndex()
        {
            FulltextIndexProvider provider = ( FulltextIndexProvider )Db.resolveDependency(typeof(IndexProviderMap)).lookup(DESCRIPTOR);
            IndexReference        indexReference;

            using (KernelTransactionImplementation transaction = KernelTransaction)
            {
                MultiTokenSchemaDescriptor multiTokenSchemaDescriptor = multiToken(new int[] { 0, 1, 2 }, EntityType.RELATIONSHIP, 0, 1, 2, 3);
                FulltextSchemaDescriptor   schema = new FulltextSchemaDescriptor(multiTokenSchemaDescriptor, new Properties());
                indexReference = transaction.SchemaWrite().indexCreate(schema, DESCRIPTOR.name(), "fulltext");
                transaction.Success();
            }
            Await(indexReference);
            long secondRelId;

            using (Transaction transaction = Db.beginTx())
            {
                Relationship ho = _node1.createRelationshipTo(_node2, RelationshipType.withName("ho"));
                secondRelId = ho.Id;
                ho.SetProperty("hej", "villa");
                ho.SetProperty("ho", "value3");
                transaction.Success();
            }
            VerifyRelationshipData(provider, secondRelId);
            Db.restartDatabase(DatabaseRule.RestartAction_Fields.EMPTY);
            provider = ( FulltextIndexProvider )Db.resolveDependency(typeof(IndexProviderMap)).lookup(DESCRIPTOR);
            VerifyRelationshipData(provider, secondRelId);
        }
Exemple #3
0
        internal static FulltextIndexDescriptor ReadOrInitialiseDescriptor(StoreIndexDescriptor descriptor, string defaultAnalyzerName, TokenHolder propertyKeyTokenHolder, File indexFolder, FileSystemAbstraction fileSystem)
        {
            Properties indexConfiguration = new Properties();

            if (descriptor.Schema() is FulltextSchemaDescriptor)
            {
                FulltextSchemaDescriptor schema = ( FulltextSchemaDescriptor )descriptor.Schema();
                indexConfiguration.putAll(Schema.IndexConfiguration);
            }
            LoadPersistedSettings(indexConfiguration, indexFolder, fileSystem);
            bool           eventuallyConsistent = bool.Parse(indexConfiguration.getProperty(INDEX_CONFIG_EVENTUALLY_CONSISTENT));
            string         analyzerName         = indexConfiguration.getProperty(INDEX_CONFIG_ANALYZER, defaultAnalyzerName);
            Analyzer       analyzer             = CreateAnalyzer(analyzerName);
            IList <string> names = new List <string>();

            foreach (int propertyKeyId in descriptor.Schema().PropertyIds)
            {
                try
                {
                    names.Add(propertyKeyTokenHolder.GetTokenById(propertyKeyId).name());
                }
                catch (TokenNotFoundException e)
                {
                    throw new System.InvalidOperationException("Property key id not found.", new PropertyKeyIdNotFoundKernelException(propertyKeyId, e));
                }
            }
            IList <string> propertyNames = Collections.unmodifiableList(names);

            return(new FulltextIndexDescriptor(descriptor, propertyNames, analyzer, analyzerName, eventuallyConsistent));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.internal.kernel.api.IndexReference createIndex(int[] entityTokens, int[] propertyIds) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException, org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException
        private IndexReference CreateIndex(int[] entityTokens, int[] propertyIds)

        {
            IndexReference fulltext;

            using (KernelTransactionImplementation transaction = KernelTransaction)
            {
                MultiTokenSchemaDescriptor multiTokenSchemaDescriptor = multiToken(entityTokens, EntityType.NODE, propertyIds);
                FulltextSchemaDescriptor   schema = new FulltextSchemaDescriptor(multiTokenSchemaDescriptor, new Properties());
                fulltext = transaction.SchemaWrite().indexCreate(schema, DESCRIPTOR.name(), NAME);
                transaction.Success();
            }
            return(fulltext);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void createAndRetainRelationshipFulltextIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CreateAndRetainRelationshipFulltextIndex()
        {
            IndexReference indexReference;

            using (KernelTransactionImplementation transaction = KernelTransaction)
            {
                MultiTokenSchemaDescriptor multiTokenSchemaDescriptor = multiToken(new int[] { 0, 1, 2 }, EntityType.RELATIONSHIP, 0, 1, 2, 3);
                FulltextSchemaDescriptor   schema = new FulltextSchemaDescriptor(multiTokenSchemaDescriptor, new Properties());
                indexReference = transaction.SchemaWrite().indexCreate(schema, DESCRIPTOR.name(), "fulltext");
                transaction.Success();
            }
            Await(indexReference);
            Db.restartDatabase(DatabaseRule.RestartAction_Fields.EMPTY);

            VerifyThatFulltextIndexIsPresent(indexReference);
        }
        public override IndexCapability GetCapability(StoreIndexDescriptor descriptor)
        {
            FulltextIndexDescriptor fulltextIndexDescriptor;

            if (descriptor is FulltextIndexDescriptor)
            {
                // We got our own index descriptor type, so we can ask it directly.
                fulltextIndexDescriptor = ( FulltextIndexDescriptor )descriptor;
                return(new FulltextIndexCapability(fulltextIndexDescriptor.EventuallyConsistent));
            }
            SchemaDescriptor schema = descriptor.Schema();

            if (schema is FulltextSchemaDescriptor)
            {
                // The fulltext schema descriptor is readily available with our settings.
                // This could be the situation where the index creation is about to be committed.
                // In that case, the schema descriptor is our own legit type, but the StoreIndexDescriptor is generic.
                FulltextSchemaDescriptor fulltextSchemaDescriptor = ( FulltextSchemaDescriptor )schema;
                return(new FulltextIndexCapability(fulltextSchemaDescriptor.EventuallyConsistent));
            }
            // The schema descriptor is probably a generic multi-token descriptor.
            // This happens if it was loaded from the schema store instead of created by our provider.
            // This would be the case when the IndexingService is starting up, and if so, we probably have an online accessor that we can ask instead.
            FulltextIndexAccessor accessor = GetOpenOnlineAccessor(descriptor);

            if (accessor != null)
            {
                fulltextIndexDescriptor = accessor.Descriptor;
                return(new FulltextIndexCapability(fulltextIndexDescriptor.EventuallyConsistent));
            }
            // All of the above has failed, so we need to load the settings in from the storage directory of the index.
            // This situation happens during recovery.
            PartitionedIndexStorage indexStorage = GetIndexStorage(descriptor.Id);

            fulltextIndexDescriptor = readOrInitialiseDescriptor(descriptor, _defaultAnalyzerName, _tokenHolders.propertyKeyTokens(), indexStorage.IndexFolder, _fileSystem);
            return(new FulltextIndexCapability(fulltextIndexDescriptor.EventuallyConsistent));
        }