当前位置: 首页>>代码示例>>C#>>正文


C# IndexWriter.Commit方法代码示例

本文整理汇总了C#中IndexWriter.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.Commit方法的具体用法?C# IndexWriter.Commit怎么用?C# IndexWriter.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IndexWriter的用法示例。


在下文中一共展示了IndexWriter.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestMmapIndex

        public virtual void TestMmapIndex()
        {
            // sometimes the directory is not cleaned by rmDir, because on Windows it
            // may take some time until the files are finally dereferenced. So clean the
            // directory up front, or otherwise new IndexWriter will fail.
            DirectoryInfo dirPath = CreateTempDir("testLuceneMmap");
            RmDir(dirPath);
            MMapDirectory dir = new MMapDirectory(dirPath, null);

            // plan to add a set of useful stopwords, consider changing some of the
            // interior filters.
            MockAnalyzer analyzer = new MockAnalyzer(Random());
            // TODO: something about lock timeouts and leftover locks.
            IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE));
            writer.Commit();
            IndexReader reader = DirectoryReader.Open(dir);
            IndexSearcher searcher = NewSearcher(reader);

            int num = AtLeast(1000);
            for (int dx = 0; dx < num; dx++)
            {
                string f = RandomField();
                Document doc = new Document();
                doc.Add(NewTextField("data", f, Field.Store.YES));
                writer.AddDocument(doc);
            }

            reader.Dispose();
            writer.Dispose();
            RmDir(dirPath);
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:31,代码来源:TestWindowsMMap.cs

示例2: TestBasic

        public virtual void TestBasic()
        {
            HashSet<string> fileExtensions = new HashSet<string>();
            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_EXTENSION);
            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_INDEX_EXTENSION);

            MockDirectoryWrapper primaryDir = new MockDirectoryWrapper(Random(), new RAMDirectory());
            primaryDir.CheckIndexOnClose = false; // only part of an index
            MockDirectoryWrapper secondaryDir = new MockDirectoryWrapper(Random(), new RAMDirectory());
            secondaryDir.CheckIndexOnClose = false; // only part of an index

            FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
            // for now we wire Lucene40Codec because we rely upon its specific impl
            bool oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;
            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
            IndexWriter writer = new IndexWriter(fsd, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetMergePolicy(NewLogMergePolicy(false)).SetCodec(Codec.ForName("Lucene40")).SetUseCompoundFile(false));
            TestIndexWriterReader.CreateIndexNoClose(true, "ram", writer);
            IndexReader reader = DirectoryReader.Open(writer, true);
            Assert.AreEqual(100, reader.MaxDoc);
            writer.Commit();
            // we should see only fdx,fdt files here
            string[] files = primaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsTrue(fileExtensions.Contains(ext));
            }
            files = secondaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            // we should not see fdx,fdt files here
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsFalse(fileExtensions.Contains(ext));
            }
            reader.Dispose();
            writer.Dispose();

            files = fsd.ListAll();
            for (int i = 0; i < files.Length; i++)
            {
                Assert.IsNotNull(files[i]);
            }
            fsd.Dispose();
            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
        }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:47,代码来源:TestFileSwitchDirectory.cs

示例3: IndexDocsWithFacetsNoTerms

 private static void IndexDocsWithFacetsNoTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter, IDictionary<string, int?> expectedCounts)
 {
     Random random = Random();
     int numDocs = AtLeast(random, 2);
     FacetsConfig config = Config;
     for (int i = 0; i < numDocs; i++)
     {
         Document doc = new Document();
         AddFacets(doc, config, false);
         indexWriter.AddDocument(config.Build(taxoWriter, doc));
     }
     indexWriter.Commit(); // flush a segment
 }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:13,代码来源:TestTaxonomyFacetCounts2.cs

示例4: IndexDocsNoFacets

 private static void IndexDocsNoFacets(IndexWriter indexWriter)
 {
     int numDocs = AtLeast(2);
     for (int i = 0; i < numDocs; i++)
     {
         Document doc = new Document();
         AddField(doc);
         indexWriter.AddDocument(doc);
     }
     indexWriter.Commit(); // flush a segment
 }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:11,代码来源:TestTaxonomyFacetCounts2.cs

示例5: IndexDictionary

		/// <summary> Index a Dictionary</summary>
		/// <param name="dict">the dictionary to index</param>
		/// <param name="mergeFactor">mergeFactor to use when indexing</param>
		/// <param name="ramMB">the max amount or memory in MB to use</param>
		/// <throws>  IOException </throws>
		/// <throws>AlreadyClosedException if the Spellchecker is already closed</throws>
		public virtual void IndexDictionary(IDictionary dict, int mergeFactor, int ramMB, CancellationToken token)
		{
			lock (modifyCurrentIndexLock)
			{
				EnsureOpen();
				Directory dir = this.spellindex;
				IndexWriter writer = new IndexWriter(spellindex, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
				writer.MergeFactor = mergeFactor;
				writer.SetMaxBufferedDocs(ramMB);

				System.Collections.IEnumerator iter = dict.GetWordsIterator();
				while (iter.MoveNext())
				{
					token.ThrowIfCancellationRequested();

					System.String word = (System.String)iter.Current;

					int len = word.Length;
					if (len < 3)
					{
						continue; // too short we bail but "too long" is fine...
					}

					if (this.Exist(word))
					{
						// if the word already exist in the gramindex
						continue;
					}

					// ok index the word
					Document doc = CreateDocument(word, GetMin(len), GetMax(len));
					writer.AddDocument(doc);
				}
				// close writer
				writer.Commit();
				writer.Dispose();
				// also re-open the spell index to see our own changes when the next suggestion
				// is fetched:
				SwapSearcher(dir);
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:47,代码来源:SpellChecker.cs

示例6: GenerateHighlights

        /// <summary>
        /// Annotates the given sequence of <see cref="Document"/> objects by adding a <b>_highlight</b> field;
        /// the <b>_highlight</b> field will contain the best matching text fragment from the <see cref="Document"/> 
        /// object's full-text field.
        /// </summary>
        /// <param name="hits">The sequence of <see cref="Document"/> objects.</param>
        /// <param name="criteria">The search criteria that produced the hits.</param>
        /// <returns>
        /// The original sequence of Document objects, with a <b>_highlight</b> field added to each Document.
        /// </returns>
        public static IEnumerable<Document> GenerateHighlights(this IEnumerable<Document> hits, SearchCriteria criteria)
        {
            if (hits == null)
                throw new ArgumentNullException(nameof(hits));
            if (criteria == null)
                throw new ArgumentNullException(nameof(criteria));
            if (String.IsNullOrWhiteSpace(criteria.Query))
                throw new ArgumentException("SearchCriteria.Query cannot be empty");

            var documents = hits.ToList();
            try
            {
                var indexDirectory = new RAMDirectory();
                var analyzer = new FullTextAnalyzer();
                var config = new IndexWriterConfig(analyzer).SetRAMBufferSizeMB(_ramBufferSizeMB);
                var writer = new IndexWriter(indexDirectory, config);

                BuidIndex(documents, writer);
                GenerateHighlights(documents, writer, criteria);

                writer.DeleteAll();
                writer.Commit();
                writer.Close();
                indexDirectory.Close();
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }

            return documents;
        }
开发者ID:cris-almodovar,项目名称:expando-db,代码行数:42,代码来源:LuceneHighlighter.cs

示例7: BuidIndex

        private static void BuidIndex(IEnumerable<Document> hits, IndexWriter writer)
        {
            foreach (var document in hits)
            {
                var doc = new FlexLucene.Document.Document();

                var idField = new StringField(Schema.StandardField.ID, document._id.ToString(), FieldStore.YES);
                doc.Add(idField);

                var fullTextField = new Field(Schema.StandardField.FULL_TEXT, document.ToLuceneFullTextString(), ExtendedTextFieldType);
                doc.Add(fullTextField);

                writer.AddDocument(doc);
            }
            writer.Commit();
        }
开发者ID:cris-almodovar,项目名称:expando-db,代码行数:16,代码来源:LuceneHighlighter.cs

示例8: indexTwoDocs

        private void indexTwoDocs(ITaxonomyWriter taxoWriter, IndexWriter indexWriter, FacetsConfig config, bool withContent)
        {
            for (int i = 0; i < 2; i++)
            {
                Document doc = new Document();
                if (withContent)
                {
                    doc.Add(new StringField("f", "a", Field.Store.NO));
                }
                if (config != null)
                {
                    doc.Add(new FacetField("A", Convert.ToString(i)));
                    indexWriter.AddDocument(config.Build(taxoWriter, doc));
                }
                else
                {
                    indexWriter.AddDocument(doc);
                }
            }

            indexWriter.Commit();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:22,代码来源:TestTaxonomyFacetCounts.cs

示例9: TestReplaceTaxonomyDirectory

        public virtual void TestReplaceTaxonomyDirectory()
        {
            Store.Directory indexDir = NewDirectory();
            Store.Directory taxoDir = NewDirectory();
            IndexWriter w = new IndexWriter(indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            var tw = new DirectoryTaxonomyWriter(taxoDir);
            w.Commit();
            tw.Commit();

            Store.Directory taxoDir2 = NewDirectory();
            var tw2 = new DirectoryTaxonomyWriter(taxoDir2);
            tw2.AddCategory(new FacetLabel("a", "b"));
            tw2.Dispose();

            var mgr = new SearcherTaxonomyManager(indexDir, taxoDir, null);
            SearcherAndTaxonomy pair = mgr.Acquire();
            try
            {
                Assert.AreEqual(1, pair.taxonomyReader.Size);
            }
            finally
            {
                mgr.Release(pair);
            }

            w.AddDocument(new Document());
            tw.ReplaceTaxonomy(taxoDir2);
            taxoDir2.Dispose();
            w.Commit();
            tw.Commit();

            mgr.MaybeRefresh();
            pair = mgr.Acquire();
            try
            {
                Assert.AreEqual(3, pair.taxonomyReader.Size);
            }
            finally
            {
                mgr.Release(pair);
            }

            IOUtils.Close(mgr, tw, w, taxoDir, indexDir);
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:44,代码来源:TestSearcherTaxonomyManager.cs

示例10: TestDirectory

        public virtual void TestDirectory()
        {
            Store.Directory indexDir = NewDirectory();
            Store.Directory taxoDir = NewDirectory();
            IndexWriter w = new IndexWriter(indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            var tw = new DirectoryTaxonomyWriter(taxoDir);
            // first empty commit
            w.Commit();
            tw.Commit();
            var mgr = new SearcherTaxonomyManager(indexDir, taxoDir, null);
            FacetsConfig config = new FacetsConfig();
            config.SetMultiValued("field", true);
            AtomicBoolean stop = new AtomicBoolean();

            // How many unique facets to index before stopping:
            int ordLimit = TEST_NIGHTLY ? 100000 : 6000;

            var indexer = new IndexerThread(w, config, tw, mgr, ordLimit, stop);
            indexer.Start();

            try
            {
                while (!stop.Get())
                {
                    SearcherAndTaxonomy pair = mgr.Acquire();
                    try
                    {
                        //System.out.println("search maxOrd=" + pair.taxonomyReader.getSize());
                        FacetsCollector sfc = new FacetsCollector();
                        pair.searcher.Search(new MatchAllDocsQuery(), sfc);
                        Facets facets = GetTaxonomyFacetCounts(pair.taxonomyReader, config, sfc);
                        FacetResult result = facets.GetTopChildren(10, "field");
                        if (pair.searcher.IndexReader.NumDocs > 0)
                        {
                            //System.out.println(pair.taxonomyReader.getSize());
                            Assert.True(result.ChildCount > 0);
                            Assert.True(result.LabelValues.Length > 0);
                        }

                        //if (VERBOSE) {
                        //System.out.println("TEST: facets=" + FacetTestUtils.toString(results.get(0)));
                        //}
                    }
                    finally
                    {
                        mgr.Release(pair);
                    }
                }
            }
            finally
            {
                indexer.Join();
            }

            if (VERBOSE)
            {
                Console.WriteLine("TEST: now stop");
            }

            IOUtils.Close(mgr, tw, w, taxoDir, indexDir);
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:61,代码来源:TestSearcherTaxonomyManager.cs

示例11: MakeEmptyIndex

 private static IndexReader MakeEmptyIndex(Random random, int numDocs)
 {
     Debug.Assert(numDocs > 0);
     Directory d = new MockDirectoryWrapper(random, new RAMDirectory());
     IndexWriter w = new IndexWriter(d, new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT, new MockAnalyzer(random)));
     for (int i = 0; i < numDocs; i++)
     {
         w.AddDocument(new Document());
     }
     w.ForceMerge(1);
     w.Commit();
     w.Dispose();
     DirectoryReader reader = DirectoryReader.Open(d);
     return new AllDeletedFilterReader(LuceneTestCase.GetOnlySegmentReader(reader));
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:15,代码来源:QueryUtils.cs

示例12: TestListenerCalled

 public virtual void TestListenerCalled()
 {
     Directory dir = NewDirectory();
     IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
     AtomicBoolean afterRefreshCalled = new AtomicBoolean(false);
     SearcherManager sm = new SearcherManager(iw, false, new SearcherFactory());
     sm.AddListener(new RefreshListenerAnonymousInnerClassHelper(this, afterRefreshCalled));
     iw.AddDocument(new Document());
     iw.Commit();
     Assert.IsFalse(afterRefreshCalled.Get());
     sm.MaybeRefreshBlocking();
     Assert.IsTrue(afterRefreshCalled.Get());
     sm.Dispose();
     iw.Dispose();
     dir.Dispose();
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:16,代码来源:TestSearcherManager.cs

示例13: TestReferenceDecrementIllegally

        public virtual void TestReferenceDecrementIllegally([ValueSource(typeof(ConcurrentMergeSchedulers), "Values")]IConcurrentMergeScheduler scheduler)
        {
            Directory dir = NewDirectory();
            var config = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))
                            .SetMergeScheduler(scheduler);
            IndexWriter writer = new IndexWriter(dir, config);
            SearcherManager sm = new SearcherManager(writer, false, new SearcherFactory());
            writer.AddDocument(new Document());
            writer.Commit();
            sm.MaybeRefreshBlocking();

            IndexSearcher acquire = sm.Acquire();
            IndexSearcher acquire2 = sm.Acquire();
            sm.Release(acquire);
            sm.Release(acquire2);

            acquire = sm.Acquire();
            acquire.IndexReader.DecRef();
            sm.Release(acquire);

            Assert.Throws<InvalidOperationException>(() => sm.Acquire(), "acquire should have thrown an InvalidOperationException since we modified the refCount outside of the manager");

            // sm.Dispose(); -- already closed
            writer.Dispose();
            dir.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:26,代码来源:TestSearcherManager.cs

示例14: TestIntermediateClose

 public virtual void TestIntermediateClose()
 {
     Directory dir = NewDirectory();
     // Test can deadlock if we use SMS:
     IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergeScheduler(new ConcurrentMergeScheduler()));
     writer.AddDocument(new Document());
     writer.Commit();
     CountdownEvent awaitEnterWarm = new CountdownEvent(1);
     CountdownEvent awaitClose = new CountdownEvent(1);
     AtomicBoolean triedReopen = new AtomicBoolean(false);
     //TaskScheduler es = Random().NextBoolean() ? null : Executors.newCachedThreadPool(new NamedThreadFactory("testIntermediateClose"));
     TaskScheduler es = Random().NextBoolean() ? null : TaskScheduler.Default;
     SearcherFactory factory = new SearcherFactoryAnonymousInnerClassHelper2(this, awaitEnterWarm, awaitClose, triedReopen, es);
     SearcherManager searcherManager = Random().NextBoolean() ? new SearcherManager(dir, factory) : new SearcherManager(writer, Random().NextBoolean(), factory);
     if (VERBOSE)
     {
         Console.WriteLine("sm created");
     }
     IndexSearcher searcher = searcherManager.Acquire();
     try
     {
         Assert.AreEqual(1, searcher.IndexReader.NumDocs);
     }
     finally
     {
         searcherManager.Release(searcher);
     }
     writer.AddDocument(new Document());
     writer.Commit();
     AtomicBoolean success = new AtomicBoolean(false);
     Exception[] exc = new Exception[1];
     ThreadClass thread = new ThreadClass(() => new RunnableAnonymousInnerClassHelper(this, triedReopen, searcherManager, success, exc).Run());
     thread.Start();
     if (VERBOSE)
     {
         Console.WriteLine("THREAD started");
     }
     awaitEnterWarm.Wait();
     if (VERBOSE)
     {
         Console.WriteLine("NOW call close");
     }
     searcherManager.Dispose();
     awaitClose.Signal();
     thread.Join();
     try
     {
         searcherManager.Acquire();
         Assert.Fail("already closed");
     }
     catch (AlreadyClosedException ex)
     {
         // expected
     }
     Assert.IsFalse(success.Get());
     Assert.IsTrue(triedReopen.Get());
     Assert.IsNull(exc[0], "" + exc[0]);
     writer.Dispose();
     dir.Dispose();
     //if (es != null)
     //{
     //    es.shutdown();
     //    es.awaitTermination(1, TimeUnit.SECONDS);
     //}
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:65,代码来源:TestSearcherManager.cs

示例15: TestReferenceDecrementIllegally

        public virtual void TestReferenceDecrementIllegally()
        {
            Directory dir = NewDirectory();
            IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergeScheduler(new ConcurrentMergeScheduler()));
            SearcherManager sm = new SearcherManager(writer, false, new SearcherFactory());
            writer.AddDocument(new Document());
            writer.Commit();
            sm.MaybeRefreshBlocking();

            IndexSearcher acquire = sm.Acquire();
            IndexSearcher acquire2 = sm.Acquire();
            sm.Release(acquire);
            sm.Release(acquire2);

            acquire = sm.Acquire();
            acquire.IndexReader.DecRef();
            sm.Release(acquire);
            try
            {
                sm.Acquire();
                Assert.Fail("acquire should have thrown an InvalidOperationException since we modified the refCount outside of the manager");
            }
            catch (InvalidOperationException ex)
            {
                //
            }

            // sm.Dispose(); -- already closed
            writer.Dispose();
            dir.Dispose();
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:31,代码来源:TestSearcherManager.cs


注:本文中的IndexWriter.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。