コード例 #1
0
ファイル: IndexProvider.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Add documents to the existing index.
        /// </summary>
        /// <param name="directoryIndexInfo">The directory infomation where the index files are located.</param>
        /// <param name="directoryFacetInfo">The directory infomation where the facet files are to be placed.</param>
        /// <param name="facetData">The complete facet information used to build the index information.</param>
        public void AddMultiFacetDocuments(DirectoryInfo directoryIndexInfo, DirectoryInfo directoryFacetInfo, FacetData facetData)
        {
            Lucene.Net.Index.IndexWriter writer      = null;
            DirectoryTaxonomyWriter      facetWriter = null;

            Lucene.Net.Store.Directory directory      = null;
            Lucene.Net.Store.Directory directoryFacet = null;

            try
            {
                if (facetData != null)
                {
                    // Create the analyzer.
                    SimpleAnalyzer   simpleAnalyzer   = new Analyzer.SimpleAnalyzer();
                    StandardAnalyzer standardAnalyzer = new Analyzer.StandardAnalyzer(simpleAnalyzer);

                    // Create the index writer.
                    directory = FSDirectory.Open(directoryIndexInfo);
                    IndexWriterConfig indexConfig = new IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48, standardAnalyzer);
                    indexConfig.SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND);

                    // Open existing or create new.
                    writer = new IndexWriter(directory, indexConfig);

                    // Create the facet writer.
                    directoryFacet = FSDirectory.Open(directoryFacetInfo);
                    facetWriter    = new DirectoryTaxonomyWriter(directoryFacet, IndexWriterConfig.OpenMode_e.APPEND);

                    // Create the facet filter.
                    FacetFilter filter = new FacetFilter();
                    filter.AddDocuments(writer, facetWriter, facetData);

                    // Commit the index.
                    writer.Commit();
                    facetWriter.Commit();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Dispose();
                }

                if (facetWriter != null)
                {
                    facetWriter.Dispose();
                }

                if (directory != null)
                {
                    directory.Dispose();
                }

                if (directoryFacet != null)
                {
                    directoryFacet.Dispose();
                }
            }
        }