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


C# Lucene.Net.Index.IndexWriter.Commit方法代码示例

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


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

示例1: TestCustomMergeScheduler

 public void TestCustomMergeScheduler()
 {
     // we don't really need to execute anything, just to make sure the custom MS
     // compiles. But ensure that it can be used as well, e.g., no other hidden
     // dependencies or something. Therefore, don't use any random API !
     Directory dir = new RAMDirectory();
     IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
     conf.SetMergeScheduler(new ReportingMergeScheduler());
     IndexWriter writer = new IndexWriter(dir, conf);
     writer.AddDocument(new Document());
     writer.Commit(); // trigger flush
     writer.AddDocument(new Document());
     writer.Commit(); // trigger flush
     writer.ForceMerge(1);
     writer.Dispose();
     dir.Dispose();
 }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:17,代码来源:TestMergeSchedulerExternal.cs

示例2: TestOutOfOrderCollection

		public virtual void  TestOutOfOrderCollection()
		{
			
			Directory dir = new RAMDirectory();
			IndexWriter writer = new IndexWriter(dir, null, MaxFieldLength.UNLIMITED);
			for (int i = 0; i < 10; i++)
			{
				writer.AddDocument(new Document());
			}
			writer.Commit();
			writer.Close();
			
			bool[] inOrder = new bool[]{false, true};
			System.String[] actualTSDCClass = new System.String[]{"OutOfOrderTopScoreDocCollector", "InOrderTopScoreDocCollector"};
			
			// Save the original value to set later.
			bool origVal = BooleanQuery.GetAllowDocsOutOfOrder();
			
			BooleanQuery.SetAllowDocsOutOfOrder(true);
			
			BooleanQuery bq = new BooleanQuery();
			// Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
			// which delegates to BS if there are no mandatory clauses.
			bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
			// Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
			// the clause instead of BQ.
			bq.SetMinimumNumberShouldMatch(1);
			try
			{
				
				IndexSearcher searcher = new IndexSearcher(dir);
				for (int i = 0; i < inOrder.Length; i++)
				{
					TopDocsCollector tdc = TopScoreDocCollector.create(3, inOrder[i]);
					Assert.AreEqual("Lucene.Net.Search.TopScoreDocCollector+" + actualTSDCClass[i], tdc.GetType().FullName);
					
					searcher.Search(new MatchAllDocsQuery(), tdc);
					
					ScoreDoc[] sd = tdc.TopDocs().scoreDocs;
					Assert.AreEqual(3, sd.Length);
					for (int j = 0; j < sd.Length; j++)
					{
						Assert.AreEqual(j, sd[j].doc, "expected doc Id " + j + " found " + sd[j].doc);
					}
				}
			}
			finally
			{
				// Whatever happens, reset BooleanQuery.allowDocsOutOfOrder to the
				// original value. Don't set it to false in case the implementation in BQ
				// will change some day.
				BooleanQuery.SetAllowDocsOutOfOrder(origVal);
			}
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:54,代码来源:TestTopScoreDocCollector.cs

示例3: TestBasic

 public virtual void  TestBasic()
 {
     HashSet<string> fileExtensions = new HashSet<string>();
     fileExtensions.Add("fdt");
     fileExtensions.Add("fdx");
     
     Directory primaryDir = new MockRAMDirectory();
     RAMDirectory secondaryDir = new MockRAMDirectory();
     
     FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
     IndexWriter writer = new IndexWriter(fsd, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
     writer.UseCompoundFile = false;
     TestIndexWriterReader.CreateIndexNoClose(true, "ram", writer);
     IndexReader reader = writer.GetReader();
     Assert.AreEqual(100, reader.MaxDoc);
     writer.Commit();
     // we should see only fdx,fdt files here
     System.String[] files = primaryDir.ListAll();
     Assert.IsTrue(files.Length > 0);
     for (int x = 0; x < files.Length; x++)
     {
         System.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++)
     {
         System.String ext = FileSwitchDirectory.GetExtension(files[x]);
         Assert.IsFalse(fileExtensions.Contains(ext));
     }
     reader.Close();
     writer.Close();
     
     files = fsd.ListAll();
     for (int i = 0; i < files.Length; i++)
     {
         Assert.IsNotNull(files[i]);
     }
     fsd.Close();
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:42,代码来源:TestFileSwitchDirectory.cs

示例4: TestOutOfOrderCollection

        public virtual void TestOutOfOrderCollection()
        {

            Directory dir = new RAMDirectory();
            IndexWriter writer = new IndexWriter(dir, null, MaxFieldLength.UNLIMITED);
            for (int i = 0; i < 10; i++)
            {
                writer.AddDocument(new Document());
            }
            writer.Commit();
            writer.Close();

            bool[] inOrder = new bool[] {false, true};
            System.String[] actualTSDCClass = new System.String[]
                                                  {"OutOfOrderTopScoreDocCollector", "InOrderTopScoreDocCollector"};

            BooleanQuery bq = new BooleanQuery();
            // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
            // which delegates to BS if there are no mandatory clauses.
            bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
            // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
            // the clause instead of BQ.
            bq.MinimumNumberShouldMatch = 1;
            IndexSearcher searcher = new IndexSearcher(dir, true);
            for (int i = 0; i < inOrder.Length; i++)
            {
                TopDocsCollector<ScoreDoc> tdc = TopScoreDocCollector.Create(3, inOrder[i]);
                Assert.AreEqual("Lucene.Net.Search.TopScoreDocCollector+" + actualTSDCClass[i], tdc.GetType().FullName);

                searcher.Search(new MatchAllDocsQuery(), tdc);

                ScoreDoc[] sd = tdc.TopDocs().ScoreDocs;
                Assert.AreEqual(3, sd.Length);
                for (int j = 0; j < sd.Length; j++)
                {
                    Assert.AreEqual(j, sd[j].Doc, "expected doc Id " + j + " found " + sd[j].Doc);
                }
            }
        }
开发者ID:synhershko,项目名称:lucene.net,代码行数:39,代码来源:TestTopScoreDocCollector.cs

示例5: 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.
            var dirPath = CreateTempDir("testLuceneMmap");
            RmDir(dirPath.FullName);
            var dir = new MMapDirectory(dirPath, null);

            // plan to add a set of useful stopwords, consider changing some of the
            // interior filters.
            using (var analyzer = new MockAnalyzer(Random()))
            {
                // TODO: something about lock timeouts and leftover locks.
                using (var writer = new IndexWriter(dir,
                    new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(
                        IndexWriterConfig.OpenMode_e.CREATE)))
                {
                    writer.Commit();
                    using (IndexReader reader = DirectoryReader.Open(dir))
                    {
                        var searcher = NewSearcher(reader);
                        var num = AtLeast(1000);
                        for (int dx = 0; dx < num; dx++)
                        {
                            var f = RandomField();
                            var doc = new Document();
                            doc.Add(NewTextField("data", f, Field.Store.YES));
                            writer.AddDocument(doc);
                        }
                    }
                }

                RmDir(dirPath.FullName);
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:36,代码来源:TestWindowsMMap.cs

示例6: SetUp

 public override void  SetUp()
 {
     base.SetUp();
     // prepare a small index with just a few documents.  
     base.SetUp();
     dir = new RAMDirectory();
     anlzr = new StandardAnalyzer(Util.Version.LUCENE_CURRENT);
     IndexWriter iw = new IndexWriter(dir, anlzr, IndexWriter.MaxFieldLength.LIMITED);
     // add docs not exactly in natural ID order, to verify we do check the order of docs by scores
     int remaining = N_DOCS;
     bool[] done = new bool[N_DOCS];
     int i = 0;
     while (remaining > 0)
     {
         if (done[i])
         {
             throw new System.Exception("to set this test correctly N_DOCS=" + N_DOCS + " must be primary and greater than 2!");
         }
         AddDoc(iw, i);
         done[i] = true;
         i = (i + 4) % N_DOCS;
         if (doMultiSegment && remaining % 3 == 0) 
         {
             iw.Commit();
         }
         remaining--;
     }
     iw.Close();
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:29,代码来源:FunctionTestSetup.cs

示例7: 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:WakeflyCBass,项目名称:lucenenet,代码行数:15,代码来源:QueryUtils.cs

示例8: indexTwoDocs

        private void indexTwoDocs(TaxonomyWriter 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:Cefa68000,项目名称:lucenenet,代码行数:22,代码来源:TestTaxonomyFacetCounts.cs

示例9: 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:Cefa68000,项目名称:lucenenet,代码行数:26,代码来源:TestSearcherManager.cs

示例10: 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:Cefa68000,项目名称:lucenenet,代码行数:16,代码来源:TestSearcherManager.cs

示例11: MakeEmptyIndex

 private static RAMDirectory MakeEmptyIndex(int numDeletedDocs)
 {
     RAMDirectory d = new RAMDirectory();
     IndexWriter w = new IndexWriter(d, new WhitespaceAnalyzer(), true, MaxFieldLength.LIMITED);
     for (int i = 0; i < numDeletedDocs; i++)
     {
         w.AddDocument(new Document());
     }
     w.Commit();
     w.DeleteDocuments(new MatchAllDocsQuery());
     w.Commit();
     
     if (0 < numDeletedDocs)
         Assert.IsTrue(w.HasDeletions(), "writer has no deletions");
     
     Assert.AreEqual(numDeletedDocs, w.MaxDoc(), "writer is missing some deleted docs");
     Assert.AreEqual(0, w.NumDocs(), "writer has non-deleted docs");
     w.Close();
     IndexReader r = IndexReader.Open(d, true);
     Assert.AreEqual(numDeletedDocs, r.NumDeletedDocs, "reader has wrong number of deleted docs");
     r.Close();
     return d;
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:23,代码来源:QueryUtils.cs

示例12: 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:WakeflyCBass,项目名称:lucenenet,代码行数:44,代码来源:TestSearcherTaxonomyManager.cs

示例13: TestRAMDirectoryNoLocking

        public virtual void TestRAMDirectoryNoLocking()
        {
            MockDirectoryWrapper dir = new MockDirectoryWrapper(Random(), new RAMDirectory());
            dir.LockFactory = NoLockFactory.DoNoLockFactory;
            dir.WrapLockFactory = false; // we are gonna explicitly test we get this back
            Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(dir.LockFactory), "RAMDirectory.setLockFactory did not take");

            IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            writer.Commit(); // required so the second open succeed
            // Create a 2nd IndexWriter.  this is normally not allowed but it should run through since we're not
            // using any locks:
            IndexWriter writer2 = null;
            try
            {
                writer2 = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND));
            }
            catch (Exception e)
            {
                Console.Out.Write(e.StackTrace);
                Assert.Fail("Should not have hit an IOException with no locking");
            }

            writer.Dispose();
            if (writer2 != null)
            {
                writer2.Dispose();
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:28,代码来源:TestLockFactory.cs

示例14: 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:WakeflyCBass,项目名称:lucenenet,代码行数:61,代码来源:TestSearcherTaxonomyManager.cs

示例15: 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:WakeflyCBass,项目名称:lucenenet,代码行数:13,代码来源:TestTaxonomyFacetCounts2.cs


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