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


C# IndexWriter.GetReader方法代码示例

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


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

示例1: TestMultiValueSource

		public virtual void  TestMultiValueSource()
		{
			Directory dir = new MockRAMDirectory();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
			Document doc = new Document();
			Field f = new Field("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
			doc.Add(f);
			
			for (int i = 0; i < 17; i++)
			{
				f.SetValue("" + i);
				w.AddDocument(doc);
				w.Commit();
			}
			
			IndexReader r = w.GetReader();
			w.Close();
			
			Assert.IsTrue(r.GetSequentialSubReaders().Length > 1);
			
			ValueSource s1 = new IntFieldSource("field");
			DocValues v1 = s1.GetValues(r);
			DocValues v2 = new MultiValueSource(s1).GetValues(r);
			
			for (int i = 0; i < r.MaxDoc(); i++)
			{
				Assert.AreEqual(v1.IntVal(i), i);
				Assert.AreEqual(v2.IntVal(i), i);
			}
			
			Lucene.Net.Search.FieldCache_Fields.DEFAULT.PurgeAllCaches();
			
			r.Close();
			dir.Close();
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:35,代码来源:TestValueSource.cs

示例2: Test_IndexReader_IsCurrent

        public void Test_IndexReader_IsCurrent()
        {
            RAMDirectory ramDir = new RAMDirectory();
            IndexWriter writer = new IndexWriter(ramDir, new KeywordAnalyzer(), true, new IndexWriter.MaxFieldLength(1000));
            Field field = new Field("TEST", "mytest", Field.Store.YES, Field.Index.ANALYZED);
            Document doc = new Document();
            doc.Add(field);
            writer.AddDocument(doc);

            IndexReader reader = writer.GetReader();

            writer.DeleteDocuments(new Lucene.Net.Index.Term("TEST", "mytest"));

            Assert.IsFalse(reader.IsCurrent());

            int resCount1 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")),100).TotalHits;
            Assert.AreEqual(1, resCount1);

            writer.Commit();

            Assert.IsFalse(reader.IsCurrent());

            int resCount2 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")),100).TotalHits;
            Assert.AreEqual(1, resCount2, "Reopen not invoked yet, resultCount must still be 1.");

            reader = reader.Reopen();
            Assert.IsTrue(reader.IsCurrent());

            int resCount3 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")), 100).TotalHits;
            Assert.AreEqual(0, resCount3, "After reopen, resultCount must be 0.");

            reader.Close();
            writer.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:34,代码来源:TestOldPatches.cs

示例3: TestSorting

		public virtual void  TestSorting()
		{
			Directory directory = new MockRAMDirectory();
			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			writer.SetMaxBufferedDocs(2);
			writer.SetMergeFactor(1000);
			writer.AddDocument(Adoc(new System.String[]{"id", "a", "title", "ipod", "str_s", "a"}));
			writer.AddDocument(Adoc(new System.String[]{"id", "b", "title", "ipod ipod", "str_s", "b"}));
			writer.AddDocument(Adoc(new System.String[]{"id", "c", "title", "ipod ipod ipod", "str_s", "c"}));
			writer.AddDocument(Adoc(new System.String[]{"id", "x", "title", "boosted", "str_s", "x"}));
			writer.AddDocument(Adoc(new System.String[]{"id", "y", "title", "boosted boosted", "str_s", "y"}));
			writer.AddDocument(Adoc(new System.String[]{"id", "z", "title", "boosted boosted boosted", "str_s", "z"}));
			
			IndexReader r = writer.GetReader();
			writer.Close();
			
			IndexSearcher searcher = new IndexSearcher(r);
			
			RunTest(searcher, true);
			RunTest(searcher, false);
			
			searcher.Close();
			r.Close();
			directory.Close();
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:25,代码来源:TestElevationComparator.cs

示例4: TestReadersWriters

        public void TestReadersWriters()
        {
            Directory dir;
            
            using(dir = new RAMDirectory())
            {
                Document doc;
                IndexWriter writer;
                IndexReader reader;

                using (writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    Field field = new Field("name", "value", Field.Store.YES,Field.Index.ANALYZED);
                    doc = new Document();
                    doc.Add(field);
                    writer.AddDocument(doc);
                    writer.Commit();

                    using (reader = writer.GetReader())
                    {
                        IndexReader r1 = reader.Reopen();
                    }

                    Assert.Throws<AlreadyClosedException>(() => reader.Reopen(), "IndexReader shouldn't be open here");
                }
                
                Assert.Throws<AlreadyClosedException>(() => writer.AddDocument(doc), "IndexWriter shouldn't be open here");

                Assert.IsTrue(dir.isOpen_ForNUnit, "RAMDirectory");
            }
            Assert.IsFalse(dir.isOpen_ForNUnit, "RAMDirectory");
        }
开发者ID:hanabi1224,项目名称:lucene.net,代码行数:32,代码来源:TestIDisposable.cs

示例5: Load

        public override Task Load(CancellationToken cancellationToken)
        {
            if (IndexReader.IndexExists(_directory))
            {
                IDictionary<string, string> commitUserData;
                using (IndexWriter indexWriter = new IndexWriter(_directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), false, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    commitUserData = indexWriter.GetReader().CommitUserData;
                }

                string value;
                if (commitUserData != null && commitUserData.TryGetValue("commitTimeStamp", out value))
                {
                    Value = DateTime.ParseExact(value, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
                }
                else
                {
                    Value = _defaultValue;
                }
            }
            else
            {
                Value = _defaultValue;
            }
            Trace.TraceInformation("LuceneCursor.Load: {0}", this);
            return Task.FromResult(true);
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:27,代码来源:LuceneCursor.cs

示例6: testMissingTerms

        public void testMissingTerms()
        {
            String fieldName = "field1";
            Directory rd = new RAMDirectory();
            var w = new IndexWriter(rd, new KeywordAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
            for (int i = 0; i < 100; i++)
            {
                var doc = new Document();
                int term = i*10; //terms are units of 10;
                doc.Add(new Field(fieldName, "" + term, Field.Store.YES, Field.Index.ANALYZED));
                w.AddDocument(doc);
            }
            IndexReader reader = w.GetReader();
            w.Close();

            TermsFilter tf = new TermsFilter();
            tf.AddTerm(new Term(fieldName, "19"));
            FixedBitSet bits = (FixedBitSet) tf.GetDocIdSet(reader);
            Assert.AreEqual(0, bits.Cardinality(), "Must match nothing");

            tf.AddTerm(new Term(fieldName, "20"));
            bits = (FixedBitSet) tf.GetDocIdSet(reader);
            Assert.AreEqual(1, bits.Cardinality(), "Must match 1");

            tf.AddTerm(new Term(fieldName, "10"));
            bits = (FixedBitSet) tf.GetDocIdSet(reader);
            Assert.AreEqual(2, bits.Cardinality(), "Must match 2");

            tf.AddTerm(new Term(fieldName, "00"));
            bits = (FixedBitSet) tf.GetDocIdSet(reader);
            Assert.AreEqual(2, bits.Cardinality(), "Must match 2");

            reader.Close();
            rd.Close();
        }
开发者ID:Nangal,项目名称:lucene.net,代码行数:35,代码来源:TermsFilterTest.cs

示例7: IndexStore

 public IndexStore(Type modelType, Directory directory, Analyzer analyzer)
 {
     ModelType = modelType;
     _directory = directory;
     _analyzer = analyzer;
     _writer = new IndexWriter(_directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
     _searcher = new IndexSearcher(_writer.GetReader());
 }
开发者ID:Kooboo,项目名称:Ecommerce,代码行数:8,代码来源:IndexStore.cs

示例8: SearcherManager

 public SearcherManager(IndexWriter writer, bool applyAllDeletes = true, ISearcherWarmer warmer = null)
 {
     _warmer = warmer;
     _currentSearcher = new IndexSearcher(writer.GetReader());
     if (_warmer != null)
     {
         writer.MergedSegmentWarmer = new WarmerWrapper(_warmer);
     }
 }
开发者ID:NielsKuhnel,项目名称:NrtManager,代码行数:9,代码来源:SearcherManager.cs

示例9: Test_SegmentTermVector_IndexOf

 public void Test_SegmentTermVector_IndexOf()
 {
     Lucene.Net.Store.RAMDirectory directory = new Lucene.Net.Store.RAMDirectory();
     Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.WhitespaceAnalyzer();
     Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(directory, analyzer, Lucene.Net.Index.IndexWriter.MaxFieldLength.LIMITED);
     Lucene.Net.Documents.Document document = new Lucene.Net.Documents.Document();
     document.Add(new Lucene.Net.Documents.Field("contents", new System.IO.StreamReader(new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes("a_ a0"))), Lucene.Net.Documents.Field.TermVector.WITH_OFFSETS));
     writer.AddDocument(document);
     Lucene.Net.Index.IndexReader reader = writer.GetReader();
     Lucene.Net.Index.TermPositionVector tpv = reader.GetTermFreqVector(0, "contents") as Lucene.Net.Index.TermPositionVector;
     //Console.WriteLine("tpv: " + tpv);
     int index = tpv.IndexOf("a_");
     Assert.AreEqual(index, 1, "See the issue: LUCENENET-183");
 }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:14,代码来源:TestOldPatches.cs

示例10: NGramLucene

        /// <summary>
        /// Create an instance of the class.
        /// </summary>
        /// <param name="indexPath"></param>
        /// <param name="create"></param>
        /// <param name="ignoreCase"></param>
        public NGramLucene(string indexPath, bool create, bool ignoreCase)
        {
            _indexPath = indexPath;
            var emptyStopWords = new HashSet<string>();
            var dirInfo = new DirectoryInfo(_indexPath);

            // These all must be disposed
            _directory = FSDirectory.Open(dirInfo);

            _analyzer = ignoreCase
                ? new StandardAnalyzer(Version.LUCENE_30, emptyStopWords)
                : new CaseSensitiveStandardAnalyzer(Version.LUCENE_30, emptyStopWords);

            _writer = new IndexWriter(_directory, _analyzer, create, IndexWriter.MaxFieldLength.UNLIMITED);
            _reader = _writer.GetReader();
        }
开发者ID:McBits,项目名称:LanguageLib,代码行数:22,代码来源:NGramLucene.cs

示例11: NearRealTimeTestTeste

        public void NearRealTimeTestTeste()
        {
            var diretorio = new RAMDirectory();
            const int quantidadeItensEsperados = 10;

            using (var escritorIndice = new IndexWriter(diretorio, LuceneUtil.ObterAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED))
            {
                for (int i = 0; i < quantidadeItensEsperados; i++)
                {
                    var documento = new Document();
                    documento.Add(new Field("id", i.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                    documento.Add(new Field("text", "aaa", Field.Store.NO, Field.Index.ANALYZED));
                    escritorIndice.AddDocument(documento);
                }

                var leitorIndice = escritorIndice.GetReader();

                var pesquisa = new IndexSearcher(leitorIndice);
                var consulta = new TermQuery(new Term("text", "aaa"));
                var resultado = pesquisa.Search(consulta, 1);

                var mensagemErro = string.Format("Resultado não encontrou {0} itens que se encaixavam", quantidadeItensEsperados);
                Assert.AreEqual(quantidadeItensEsperados, resultado.TotalHits, mensagemErro);

                var outroDocumento = new Document();
                escritorIndice.DeleteDocuments(new Term("id", "7"));
                outroDocumento.Add(new Field("id", "11", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                outroDocumento.Add(new Field("text", "bbb", Field.Store.NO, Field.Index.ANALYZED));
                escritorIndice.AddDocument(outroDocumento);

                var novoLeitor = leitorIndice.Reopen();
                Assert.AreNotSame(novoLeitor, leitorIndice);
                leitorIndice.Close();

                pesquisa = new IndexSearcher(novoLeitor);
                resultado = pesquisa.Search(consulta, 10);
                Assert.AreEqual(9, resultado.TotalHits, string.Format("Não encontrou {0} como quantidade esperada.", quantidadeItensEsperados - 1));

                consulta = new TermQuery(new Term("text", "bbb"));
                resultado = pesquisa.Search(consulta, 1);
                Assert.AreEqual(1, resultado.TotalHits);

                novoLeitor.Close();
            }
        }
开发者ID:diegocaxito,项目名称:LuceneTest,代码行数:45,代码来源:NearRealTimeTest.cs

示例12: TestReadersWriters

        public void TestReadersWriters()
        {
            Directory dir;
            
            using(dir = new RAMDirectory())
            {
                Document doc;
                IndexWriter writer;
                IndexReader reader;

                using (writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true))
                {
                    Field field = new Field("name", "value", Field.Store.YES,Field.Index.ANALYZED);
                    doc = new Document();
                    doc.Add(field);
                    writer.AddDocument(doc);
                    writer.Commit();

                    using (reader = writer.GetReader())
                    {
                        IndexReader r1 =  reader.Reopen();
                    }

                    try
                    {
                        IndexReader r2 = reader.Reopen();
                        Assert.Fail("IndexReader shouldn't be open here");
                    }
                    catch (AlreadyClosedException)
                    {
                    }
                }
                try
                {
                    writer.AddDocument(doc);
                    Assert.Fail("IndexWriter shouldn't be open here");
                }
                catch (AlreadyClosedException)
                {
                }

                Assert.IsTrue(dir.isOpen_ForNUnit, "RAMDirectory");
            }
            Assert.IsFalse(dir.isOpen_ForNUnit, "RAMDirectory");
        }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:45,代码来源:TestIDisposable.cs

示例13: TestIndexing

		public virtual void  TestIndexing()
		{
			Directory mainDir = new MockRAMDirectory();
			IndexWriter writer = new IndexWriter(mainDir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			writer.UseCompoundFile = false;
			IndexReader reader = writer.GetReader(); // start pooling readers
			reader.Close();
			writer.MergeFactor = 2;
			writer.SetMaxBufferedDocs(10);
			RunThread[] indexThreads = new RunThread[4];
			for (int x = 0; x < indexThreads.Length; x++)
			{
				indexThreads[x] = new RunThread(this, x % 2, writer);
				indexThreads[x].Name = "Thread " + x;
				indexThreads[x].Start();
			}
			long startTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
			long duration = 5 * 1000;
			while (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - startTime) < duration)
			{
				System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 100));
			}
			int delCount = 0;
			int addCount = 0;
			for (int x = 0; x < indexThreads.Length; x++)
			{
				indexThreads[x].run_Renamed_Field = false;
				Assert.IsTrue(indexThreads[x].ex == null);
				addCount += indexThreads[x].addCount;
				delCount += indexThreads[x].delCount;
			}
			for (int x = 0; x < indexThreads.Length; x++)
			{
				indexThreads[x].Join();
			}
			//System.out.println("addCount:"+addCount);
			//System.out.println("delCount:"+delCount);
			writer.Close();
			mainDir.Close();
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:40,代码来源:TestNRTReaderWithThreads.cs

示例14: Index

    /// <summary>
    /// This method indexes the content that is sent across to it. Each piece of content (or "document")
    /// that is indexed has to have a unique identifier (so that the caller can take action based on the
    /// document id). Therefore, this method accepts key-value pairs in the form of a dictionary. The key
    /// is a ulong which uniquely identifies the string to be indexed. The string itself is the value
    /// within the dictionary for that key. Be aware that stop words (like the, this, at, etc.) are _not_
    /// indexed.
    /// </summary>
    /// <param name="txtIdPairToBeIndexed">A dictionary of key-value pairs that are sent by the caller
    /// to uniquely identify each string that is to be indexed.</param>
    /// <returns>The number of documents indexed.</returns>
    public int Index (Dictionary<long, string> txtIdPairToBeIndexed) {

		using (Directory directory = FSDirectory.Open(_indexDir))
		using (Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
		using (IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
		using (IndexReader reader = writer.GetReader())
		{

			//writer.DeleteAll();


			Dictionary<long, string>.KeyCollection keys = txtIdPairToBeIndexed.Keys;

			foreach (long id in keys)
			{
				char[] delimiter = { ';' };
				string[] text = txtIdPairToBeIndexed[id].Split(delimiter);
				Document document = new Document();

				Field title = new	Field("title", text[0], Field.Store.YES, Field.Index.NO);
				Field type = new Field("type", text[1], Field.Store.YES, Field.Index.NO);
				Field idField = new Field("date", (id).ToString(), Field.Store.YES, Field.Index.ANALYZED);

				document.Add(title);
				document.Add(type);
				document.Add(idField);

				writer.AddDocument(document);
			}

			int numIndexed = writer.GetDocCount(0);//TODO check number
			writer.Optimize();
			writer.Flush(true,true,true);

			return numIndexed;
		}

		}
开发者ID:irfiit,项目名称:wikipedia,代码行数:49,代码来源:IndexMaker.cs

示例15: TestAfterClose

        public virtual void  TestAfterClose()
        {
            Directory dir1 = new MockRAMDirectory();
            IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
            writer.SetInfoStream(infoStream);
            
            // create the index
            CreateIndexNoClose(false, "test", writer);
            
            IndexReader r = writer.GetReader();
            writer.Close();
            
            _TestUtil.CheckIndex(dir1);
            
            // reader should remain usable even after IndexWriter is closed:
            Assert.AreEqual(100, r.NumDocs());
            Query q = new TermQuery(new Term("indexname", "test"));
            Assert.AreEqual(100, new IndexSearcher(r).Search(q, 10).TotalHits);

            Assert.Throws<AlreadyClosedException>(() => r.Reopen(), "failed to hit AlreadyClosedException");

            r.Close();
            dir1.Close();
        }
开发者ID:Nangal,项目名称:lucene.net,代码行数:24,代码来源:TestIndexWriterReader.cs


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