コード例 #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Ensures that open writer. </summary>
        ///
        /// <remarks>   Semantika d.o.o.,. </remarks>
        ///
        /// <param name="recreateIndex">  (Optional) True to recreate index. </param>
        /// <param name="indexType">      (Optional) Type of the index. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        private void EnsureOpenWriter(bool recreateIndex = false, IndexType?indexType = null)
        {
            if (IsReadOnly)
            {
                throw new InvalidOperationException("The Index has been open as read only!");
            }

            //If we get the type of index we need, we open just that type, otherwise we open all supported types
            IEnumerable <IndexType> typesToOpen = GetIndexTypesArray(indexType);

            //lock (m_indexIOLock)
            {
                //Go through al lrequested index types
                foreach (var currentIndexType in typesToOpen)
                {
                    var currentManagementObjects = m_managementObjects[currentIndexType];

                    //Create writer instances
                    if (currentManagementObjects.Writer == null || currentManagementObjects.Writer.IsClosed)
                    {
                        //Configure the basic index configuration to use the main analyzer, and commit everything on close
                        IndexWriterConfig iwic = new IndexWriterConfig(LuceneVersion.LUCENE_48, new StandardAnalyzer(LuceneVersion.LUCENE_48));
                        if (recreateIndex)
                        {
                            iwic.SetOpenMode(OpenMode.CREATE);
                        }
                        else
                        {
                            iwic.SetOpenMode(OpenMode.CREATE_OR_APPEND);
                        }
                        iwic.SetMaxThreadStates(12);
                        currentManagementObjects.Writer = new IndexWriter(currentManagementObjects.Directory, iwic);
                    }
                }
            }
        }