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


C# Search.IndexSearcher类代码示例

本文整理汇总了C#中Lucene.Net.Search.IndexSearcher的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Search.IndexSearcher类的具体用法?C# Lucene.Net.Search.IndexSearcher怎么用?C# Lucene.Net.Search.IndexSearcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TestMmapIndex

        public virtual void  TestMmapIndex()
        {
            Assert.Ignore("Need to port tests, but we don't really support MMapDirectories anyway");

            FSDirectory storeDirectory;
            storeDirectory = new MMapDirectory(new System.IO.DirectoryInfo(storePathname), null);
            
            // plan to add a set of useful stopwords, consider changing some of the
            // interior filters.
            StandardAnalyzer analyzer = new StandardAnalyzer(Util.Version.LUCENE_CURRENT, Support.Compatibility.SetFactory.CreateHashSet<string>());
            // TODO: something about lock timeouts and leftover locks.
            IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
            IndexSearcher searcher = new IndexSearcher(storeDirectory, true);
            
            for (int dx = 0; dx < 1000; dx++)
            {
                System.String f = RandomField();
                Document doc = new Document();
                doc.Add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED));
                writer.AddDocument(doc);
            }
            
            searcher.Close();
            writer.Close();
            RmDir(new System.IO.FileInfo(storePathname));
        }
开发者ID:Nangal,项目名称:lucene.net,代码行数:26,代码来源:TestWindowsMMap.cs

示例2: TestDemo_Renamed_Method

		public virtual void  TestDemo_Renamed_Method()
		{
			
			Analyzer analyzer = new StandardAnalyzer();
			
			// Store the index in memory:
			Directory directory = new RAMDirectory();
			// To store an index on disk, use this instead (note that the 
			// parameter true will overwrite the index in that directory
			// if one exists):
			//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
			IndexWriter iwriter = new IndexWriter(directory, analyzer, true);
			iwriter.SetMaxFieldLength(25000);
			Document doc = new Document();
			System.String text = "This is the text to be indexed.";
			doc.Add(new Field("fieldname", text, Field.Store.YES, Field.Index.TOKENIZED));
			iwriter.AddDocument(doc);
			iwriter.Close();
			
			// Now search the index:
			IndexSearcher isearcher = new IndexSearcher(directory);
			// Parse a simple query that searches for "text":
			Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("fieldname", analyzer);
			Query query = parser.Parse("text");
			Hits hits = isearcher.Search(query);
			Assert.AreEqual(1, hits.Length());
			// Iterate through the results:
			for (int i = 0; i < hits.Length(); i++)
			{
				Document hitDoc = hits.Doc(i);
				Assert.AreEqual("This is the text to be indexed.", hitDoc.Get("fieldname"));
			}
			isearcher.Close();
			directory.Close();
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:35,代码来源:TestDemo.cs

示例3: TestDemo_Renamed

		public virtual void  TestDemo_Renamed()
		{
			
			Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
			
			// Store the index in memory:
			Directory directory = new RAMDirectory();
			// To store an index on disk, use this instead:
			//Directory directory = FSDirectory.open("/tmp/testindex");
			IndexWriter iwriter = new IndexWriter(directory, analyzer, true, new IndexWriter.MaxFieldLength(25000));
			Document doc = new Document();
			System.String text = "This is the text to be indexed.";
			doc.Add(new Field("fieldname", text, Field.Store.YES, Field.Index.ANALYZED));
			iwriter.AddDocument(doc);
			iwriter.Close();
			
			// Now search the index:
			IndexSearcher isearcher = new IndexSearcher(directory, true); // read-only=true
			// Parse a simple query that searches for "text":
			QueryParser parser = new QueryParser("fieldname", analyzer);
			Query query = parser.Parse("text");
			ScoreDoc[] hits = isearcher.Search(query, null, 1000).scoreDocs;
			Assert.AreEqual(1, hits.Length);
			// Iterate through the results:
			for (int i = 0; i < hits.Length; i++)
			{
				Document hitDoc = isearcher.Doc(hits[i].doc);
				Assert.AreEqual(hitDoc.Get("fieldname"), "This is the text to be indexed.");
			}
			isearcher.Close();
			directory.Close();
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:32,代码来源:TestDemo.cs

示例4: SetUp

		public override void  SetUp()
		{
			base.SetUp();
			RAMDirectory directory = new RAMDirectory();
			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			for (int i = 0; i < docFields.Length; i++)
			{
				Document doc = new Document();
				doc.Add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
				writer.AddDocument(doc);
			}
			writer.Close();
			searcher = new IndexSearcher(directory);
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:14,代码来源:TestNearSpansOrdered.cs

示例5: SetUp

		public virtual void  SetUp()
		{
			RAMDirectory directory = new RAMDirectory();
			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
			System.Text.StringBuilder buffer = new System.Text.StringBuilder();
			for (int i = 0; i < docFields.Length; i++)
			{
				Document doc = new Document();
				doc.Add(Field.Text(field, docFields[i]));
				writer.AddDocument(doc);
			}
			writer.Close();
			searcher = new IndexSearcher(directory);
		}
开发者ID:emtees,项目名称:old-code,代码行数:14,代码来源:TestSpans.cs

示例6: SetUp

		public override void SetUp()
		{
			base.SetUp();
			RAMDirectory directory = new RAMDirectory();
			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
			for (int i = 0; i < docFields.Length; i++)
			{
				Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
				doc.Add(new Field(field, docFields[i], Field.Store.YES, Field.Index.TOKENIZED));
				writer.AddDocument(doc);
			}
			writer.Close();
			searcher = new IndexSearcher(directory);
			//System.out.println("set up " + getName());
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:15,代码来源:TestSpans.cs

示例7: SetUp

		public override void SetUp()
		{
			base.SetUp();
			directory = new RAMDirectory();
			IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
			
			Document doc = new Document();
			doc.Add(new Field("partnum", "Q36", Field.Store.YES, Field.Index.UN_TOKENIZED));
			doc.Add(new Field("description", "Illidium Space Modulator", Field.Store.YES, Field.Index.TOKENIZED));
			writer.AddDocument(doc);
			
			writer.Close();
			
			searcher = new IndexSearcher(directory);
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:15,代码来源:TestKeywordAnalyzer.cs

示例8: SetUp

 public override void  SetUp()
 {
     base.SetUp();
     RAMDirectory directory = new RAMDirectory();
     IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
     //writer.infoStream = System.out;
     for (int i = 0; i < 1000; i++)
     {
         Document doc = new Document();
         doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
         writer.AddDocument(doc);
     }
     
     writer.Close();
     
     searcher = new IndexSearcher(directory, true);
 }
开发者ID:Nangal,项目名称:lucene.net,代码行数:17,代码来源:TestBasics.cs

示例9: TestIterator

		public virtual void  TestIterator()
		{
			RAMDirectory directory = new RAMDirectory();
			
			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			Document doc = new Document();
			doc.Add(new Field("field", "iterator test doc 1", Field.Store.YES, Field.Index.ANALYZED));
			writer.AddDocument(doc);
			
			doc = new Document();
			doc.Add(new Field("field", "iterator test doc 2", Field.Store.YES, Field.Index.ANALYZED));
			writer.AddDocument(doc);
			
			writer.Close();
			
			_TestUtil.CheckIndex(directory);
			
			IndexSearcher searcher = new IndexSearcher(directory);
			Hits hits = searcher.Search(new TermQuery(new Term("field", "iterator")));
			
			HitIterator iterator = (HitIterator) hits.Iterator();
			Assert.AreEqual(2, iterator.Length());
			Assert.IsTrue(iterator.MoveNext());
			Hit hit = (Hit) iterator.Current;
			Assert.AreEqual("iterator test doc 1", hit.Get("field"));
			
			Assert.IsTrue(iterator.MoveNext());
			hit = (Hit) iterator.Current;
			Assert.AreEqual("iterator test doc 2", hit.GetDocument().Get("field"));
			
			Assert.IsFalse(iterator.MoveNext());
			
			bool caughtException = false;
			try
			{
				System.Object generatedAux = iterator.Current;
			}
			catch (System.ArgumentOutOfRangeException e)
			{
				Assert.IsTrue(true);
				caughtException = true;
			}
			
			Assert.IsTrue(caughtException);
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:45,代码来源:TestHitIterator.cs

示例10: Main

        public static void Main(System.String[] args)
        {
            System.String index = @"c:\EmailTest\LuceneDB";
            IndexReader reader = IndexReader.Open(FSDirectory.Open(new System.IO.FileInfo(index)), true); // only searching, so read-only=true
            Searcher searcher = new IndexSearcher(reader);

            if (Stopwatch.IsHighResolution) {
                System.Console.WriteLine("We have a high resolution timer with an frequency of {0} ticks/ms", Stopwatch.Frequency/1000);
            }

            searchFor(searcher, "jeske AND neotonic");
            searchFor(searcher, "noticed AND problems");
            searchFor(searcher, "data AND returned");
            searchFor(searcher, "scott AND hassan");

            searcher.Close();
            reader.Close();
            System.Console.WriteLine("done");
        }
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:19,代码来源:BendSearchTest.cs

示例11: PreviouslyIndexed

        public static bool PreviouslyIndexed(string url)
        {
            string indexFileLocation = indexDir;
            Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, false);
            Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir);
            Lucene.Net.Search.Hits hits = null;
            try
            {
                Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("url", url));

                hits = searcher.Search(query);

            }
            catch { }
            finally
            {
                searcher.Close();
            }
            return hits.Length() > 0;
        }
开发者ID:eulalie367,项目名称:littleapps,代码行数:20,代码来源:Program.cs

示例12: SearchProjects

        public static List<IndexedItem> SearchProjects(string s)
        {
            List<IndexedItem> retVal = new List<IndexedItem>();

            string indexFileLocation = indexDir;
            Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, false);
            Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir);

            try
            {
                Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("content", s));
                query = query.Combine(new Lucene.Net.Search.Query[] { query, new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("url", fromUrl)) });
                query = query.Combine(new Lucene.Net.Search.Query[] { query, new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("title", s)) });

                //execute the query
                Lucene.Net.Search.Hits hits = searcher.Search(query);

                //iterate over the results.
                for (int i = 0; i < hits.Length(); i++)
                {
                    Lucene.Net.Documents.Document doc = hits.Doc(i);
                    string article = doc.Get("content");
                    string title = doc.Get("title");
                    string url = doc.Get("url");
                    retVal.Add(new IndexedItem { Article = article, Href = url, Title = title });
                }
                foreach (IndexedItem ind in retVal)
                {
                    Console.WriteLine(ind.Href);
                }

                retVal = retVal.Distinct().ToList();
            }
            catch { }
            finally
            {
                searcher.Close();
            }
            return retVal;
        }
开发者ID:eulalie367,项目名称:littleapps,代码行数:40,代码来源:Program.cs

示例13: CreateWeight

        public override Weight CreateWeight(IndexSearcher searcher)
        {
            Weight baseWeight = baseQuery.CreateWeight(searcher);
            object[] drillDowns = new object[drillDownQueries.Length];
            for (int dim = 0; dim < drillDownQueries.Length; dim++)
            {
                Query query = drillDownQueries[dim];
                Filter filter = DrillDownQuery.GetFilter(query);
                if (filter != null)
                {
                    drillDowns[dim] = filter;
                }
                else
                {
                    // TODO: would be nice if we could say "we will do no
                    // scoring" here....
                    drillDowns[dim] = searcher.Rewrite(query).CreateWeight(searcher);
                }
            }

            return new WeightAnonymousInnerClassHelper(this, baseWeight, drillDowns);
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:22,代码来源:DrillSidewaysQuery.cs

示例14: TestMmapIndex

		public virtual void  TestMmapIndex()
		{
			FSDirectory storeDirectory;
			storeDirectory = FSDirectory.GetDirectory(storePathname);
			
			// plan to add a set of useful stopwords, consider changing some of the
			// interior filters.
			StandardAnalyzer analyzer = new StandardAnalyzer(new System.Collections.Hashtable());
			// TODO: something about lock timeouts and leftover locks.
			IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true);
			IndexSearcher searcher = new IndexSearcher(storePathname);
			
			for (int dx = 0; dx < 1000; dx++)
			{
				System.String f = RandomField();
				Document doc = new Document();
				doc.Add(new Field("data", f, Field.Store.YES, Field.Index.TOKENIZED));
				writer.AddDocument(doc);
			}
			
			searcher.Close();
			writer.Close();
			RmDir(new System.IO.FileInfo(storePathname));
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:24,代码来源:TestWindowsMMap.cs

示例15: DoTestRank

		// Test that queries based on reverse/ordFieldScore scores correctly
		private void  DoTestRank(System.String field, bool inOrder)
		{
			IndexSearcher s = new IndexSearcher(dir, true);
			ValueSource vs;
			if (inOrder)
			{
				vs = new OrdFieldSource(field);
			}
			else
			{
				vs = new ReverseOrdFieldSource(field);
			}
			
			Query q = new ValueSourceQuery(vs);
			Log("test: " + q);
			QueryUtils.Check(q, s);
			ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
			Assert.AreEqual(N_DOCS, h.Length, "All docs should be matched!");
			System.String prevID = inOrder?"IE":"IC"; // smaller than all ids of docs in this test ("ID0001", etc.)
			
			for (int i = 0; i < h.Length; i++)
			{
				System.String resID = s.Doc(h[i].Doc).Get(ID_FIELD);
				Log(i + ".   score=" + h[i].Score + "  -  " + resID);
				Log(s.Explain(q, h[i].Doc));
				if (inOrder)
				{
					Assert.IsTrue(String.CompareOrdinal(resID, prevID) < 0, "res id " + resID + " should be < prev res id " + prevID);
				}
				else
				{
					Assert.IsTrue(String.CompareOrdinal(resID, prevID) > 0, "res id " + resID + " should be > prev res id " + prevID);
				}
				prevID = resID;
			}
		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:37,代码来源:TestOrdValues.cs


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