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


C# Search.Query类代码示例

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


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

示例1: CustomScoreQuery

		/// <summary> Create a CustomScoreQuery over input subQuery and a {@link ValueSourceQuery}.</summary>
		/// <param name="subQuery">the sub query whose score is being customized. Must not be null.
		/// </param>
		/// <param name="valSrcQueries">value source queries whose scores are used in the custom score
		/// computation. For most simple/convenient use case these would be 
		/// {@link Lucene.Net.Search.Function.FieldScoreQuery FieldScoreQueries}.
		/// This parameter is optional - it can be null or even an empty array.
		/// </param>
		public CustomScoreQuery(Query subQuery, ValueSourceQuery[] valSrcQueries)
		{
			this.subQuery = subQuery;
			this.valSrcQueries = valSrcQueries != null?valSrcQueries:new ValueSourceQuery[0];
			if (subQuery == null)
				throw new System.ArgumentException("<subquery> must not be null!");
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:15,代码来源:CustomScoreQuery.cs

示例2: DrillSidewaysQuery

 internal DrillSidewaysQuery(Query baseQuery, Collector drillDownCollector,
     Collector[] drillSidewaysCollectors, Query[] drillDownQueries, bool scoreSubDocsAtOnce)
 {
     this.baseQuery = baseQuery;
     this.drillDownCollector = drillDownCollector;
     this.drillSidewaysCollectors = drillSidewaysCollectors;
     this.drillDownQueries = drillDownQueries;
     this.scoreSubDocsAtOnce = scoreSubDocsAtOnce;
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:9,代码来源:DrillSidewaysQuery.cs

示例3: GetIdfWeightedTerms

		/// <summary> Extracts all terms texts of a given Query into an array of WeightedTerms
		/// 
		/// </summary>
		/// <param name="query">     Query to extract term texts from
		/// </param>
		/// <param name="reader">used to compute IDF which can be used to a) score selected fragments better 
		/// b) use graded highlights eg chaning intensity of font color
		/// </param>
		/// <param name="fieldName">the field on which Inverse Document Frequency (IDF) calculations are based
		/// </param>
		/// <returns> an array of the terms used in a query, plus their weights.
		/// </returns>
		public static WeightedTerm[] GetIdfWeightedTerms(Query query, IndexReader reader, System.String fieldName)
		{
			WeightedTerm[] terms = GetTerms(query, false, fieldName);
			int totalNumDocs = reader.NumDocs();
			for (int i = 0; i < terms.Length; i++)
			{
				try
				{
					int docFreq = reader.DocFreq(new Term(fieldName, terms[i].term));
					//IDF algorithm taken from DefaultSimilarity class
					float idf = (float) (System.Math.Log((float) totalNumDocs / (double) (docFreq + 1)) + 1.0);
					terms[i].weight *= idf;
				}
				catch (System.IO.IOException e)
				{
					//ignore 
				}
			}
			return terms;
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:32,代码来源:QueryTermExtractor.cs

示例4: VerifyResults

		// verify results are as expected.
		private void  VerifyResults(float boost, IndexSearcher s, System.Collections.Hashtable h1, System.Collections.Hashtable h2customNeutral, System.Collections.Hashtable h3CustomMul, System.Collections.Hashtable h4CustomAdd, System.Collections.Hashtable h5CustomMulAdd, Query q1, Query q2, Query q3, Query q4, Query q5)
		{
			
			// verify numbers of matches
			Log("#hits = " + h1.Count);
			Assert.AreEqual(h1.Count, h2customNeutral.Count, "queries should have same #hits");
			Assert.AreEqual(h1.Count, h3CustomMul.Count, "queries should have same #hits");
			Assert.AreEqual(h1.Count, h4CustomAdd.Count, "queries should have same #hits");
			Assert.AreEqual(h1.Count, h5CustomMulAdd.Count, "queries should have same #hits");
			
			// verify scores ratios
			for (System.Collections.IEnumerator it = h1.Keys.GetEnumerator(); it.MoveNext(); )
			{
				System.Int32 x = (System.Int32) it.Current;
				
				int doc = x;
				Log("doc = " + doc);
				
				float fieldScore = ExpectedFieldScore(s.GetIndexReader().Document(doc).Get(ID_FIELD));
				Log("fieldScore = " + fieldScore);
				Assert.IsTrue(fieldScore > 0, "fieldScore should not be 0");
				
				float score1 = (float) ((System.Single) h1[x]);
				LogResult("score1=", s, q1, doc, score1);
				
				float score2 = (float) ((System.Single) h2customNeutral[x]);
				LogResult("score2=", s, q2, doc, score2);
				Assert.AreEqual(boost * score1, score2, TEST_SCORE_TOLERANCE_DELTA, "same score (just boosted) for neutral");
				
				float score3 = (float) ((System.Single) h3CustomMul[x]);
				LogResult("score3=", s, q3, doc, score3);
				Assert.AreEqual(boost * fieldScore * score1, score3, TEST_SCORE_TOLERANCE_DELTA, "new score for custom mul");
				
				float score4 = (float) ((System.Single) h4CustomAdd[x]);
				LogResult("score4=", s, q4, doc, score4);
				Assert.AreEqual(boost * (fieldScore + score1), score4, TEST_SCORE_TOLERANCE_DELTA, "new score for custom add");
				
				float score5 = (float) ((System.Single) h5CustomMulAdd[x]);
				LogResult("score5=", s, q5, doc, score5);
				Assert.AreEqual(boost * fieldScore * (score1 + fieldScore), score5, TEST_SCORE_TOLERANCE_DELTA, "new score for custom mul add");
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:43,代码来源:TestCustomScoreQuery.cs

示例5: TestGetRangeFragments

        public virtual void  TestGetRangeFragments()
		{
			System.String queryString = FIELD_NAME + ":[kannedy TO kznnedy]";
			
			//Need to explicitly set the QueryParser property to use RangeQuery rather than RangeFilters
			QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer());
			parser.SetUseOldRangeQuery(true);
			query = parser.Parse(queryString);
			DoSearching(query);
			
			DoStandardHighlights();
			Assert.IsTrue(numHighlights == 5, "Failed to find correct number of highlights " + numHighlights + " found");
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:13,代码来源:HighlighterTest.cs

示例6: DumbQueryWrapper

			public DumbQueryWrapper(Query q):base()
			{
				this.q = q;
			}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:4,代码来源:TestMultiAnalyzer.cs

示例7: AddClause

		protected internal virtual void  AddClause(System.Collections.ArrayList clauses, int conj, int mods, Query q)
		{
			AddClause((System.Collections.IList) clauses, conj, mods, q);
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:4,代码来源:QueryParser.cs

示例8: NewBooleanClause

		/// <summary> Builds a new BooleanClause instance</summary>
		/// <param name="q">sub query
		/// </param>
		/// <param name="occur">how this clause should occur when matching documents
		/// </param>
		/// <returns> new BooleanClause instance
		/// </returns>
		protected internal virtual BooleanClause NewBooleanClause(Query q, BooleanClause.Occur occur)
		{
			return new BooleanClause(q, occur);
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:11,代码来源:QueryParser.cs

示例9: QueryScorer

		/// <summary> </summary>
		/// <param name="query">a Lucene query (ideally rewritten using query.rewrite 
		/// before being passed to this class and the searcher)
		/// </param>
		/// <param name="fieldName">the Field name which is used to match Query terms
		/// </param>
		public QueryScorer(Query query, System.String fieldName):this(QueryTermExtractor.GetTerms(query, false, fieldName))
		{
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:9,代码来源:QueryScorer.cs

示例10: DoSearching

		public virtual void  DoSearching(System.String queryString)
		{
			QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer());
            parser.SetMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
			query = parser.Parse(queryString);
			DoSearching(query);
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:7,代码来源:HighlighterTest.cs

示例11: QueryTest

		private void  QueryTest(Query query)
		{
			ScoreDoc[] parallelHits = parallel.Search(query, null, 1000).scoreDocs;
			ScoreDoc[] singleHits = single.Search(query, null, 1000).scoreDocs;
			Assert.AreEqual(parallelHits.Length, singleHits.Length);
			for (int i = 0; i < parallelHits.Length; i++)
			{
				Assert.AreEqual(parallelHits[i].score, singleHits[i].score, 0.001f);
				Document docParallel = parallel.Doc(parallelHits[i].doc);
				Document docSingle = single.Doc(singleHits[i].doc);
				Assert.AreEqual(docParallel.Get("f1"), docSingle.Get("f1"));
				Assert.AreEqual(docParallel.Get("f2"), docSingle.Get("f2"));
				Assert.AreEqual(docParallel.Get("f3"), docSingle.Get("f3"));
				Assert.AreEqual(docParallel.Get("f4"), docSingle.Get("f4"));
			}
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:16,代码来源:TestParallelReader.cs

示例12: DeleteDocuments

		/// <summary> Deletes the document(s) matching any of the provided queries.
		/// All deletes are flushed at the same time.
		/// 
		/// <p/><b>NOTE</b>: if this method hits an OutOfMemoryError
		/// you should immediately close the writer.  See <a
		/// href="#OOME">above</a> for details.<p/>
		/// 
		/// </summary>
		/// <param name="queries">array of queries to identify the documents
		/// to be deleted
		/// </param>
		/// <throws>  CorruptIndexException if the index is corrupt </throws>
		/// <throws>  IOException if there is a low-level IO error </throws>
		public virtual void  DeleteDocuments(Query[] queries)
		{
			EnsureOpen();
			bool doFlush = docWriter.BufferDeleteQueries(queries);
			if (doFlush)
				Flush(true, false, false);
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:20,代码来源:IndexWriter.cs

示例13: AddDeleteQuery

 private void AddDeleteQuery(Query query, int docID)
 {
     lock (this) { deletesInRAM.queries[query] = flushedDocCount + docID; }
 }
开发者ID:cqm0609,项目名称:lucene-file-finder,代码行数:4,代码来源:DocumentsWriter.cs

示例14: LogResult

		private void  LogResult(System.String msg, IndexSearcher s, Query q, int doc, float score1)
		{
			QueryUtils.Check(q, s);
			Log(msg + " " + score1);
			Log("Explain by: " + q);
			Log(s.Explain(q, doc));
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:7,代码来源:TestCustomScoreQuery.cs

示例15: TestMultiSearcher

		public virtual void  TestMultiSearcher()
		{
			//setup index 1
			RAMDirectory ramDir1 = new RAMDirectory();
			IndexWriter writer1 = new IndexWriter(ramDir1, new StandardAnalyzer(), true);
			Document d = new Document();
			Field f = new Field(FIELD_NAME, "multiOne", Field.Store.YES, Field.Index.TOKENIZED);
			d.Add(f);
			writer1.AddDocument(d);
			writer1.Optimize();
			writer1.Close();
			IndexReader reader1 = IndexReader.Open(ramDir1);
			
			//setup index 2
			RAMDirectory ramDir2 = new RAMDirectory();
			IndexWriter writer2 = new IndexWriter(ramDir2, new StandardAnalyzer(), true);
			d = new Document();
			f = new Field(FIELD_NAME, "multiTwo", Field.Store.YES, Field.Index.TOKENIZED);
			d.Add(f);
			writer2.AddDocument(d);
			writer2.Optimize();
			writer2.Close();
			IndexReader reader2 = IndexReader.Open(ramDir2);
			
			
			
			IndexSearcher[] searchers = new IndexSearcher[2];
			searchers[0] = new IndexSearcher(ramDir1);
			searchers[1] = new IndexSearcher(ramDir2);
			MultiSearcher multiSearcher = new MultiSearcher(searchers);
			QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer());
            parser.SetMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
			query = parser.Parse("multi*");
			System.Console.Out.WriteLine("Searching for: " + query.ToString(FIELD_NAME));
			//at this point the multisearcher calls combine(query[])
			hits = multiSearcher.Search(query);
			
			//query = QueryParser.parse("multi*", FIELD_NAME, new StandardAnalyzer());
			Query[] expandedQueries = new Query[2];
			expandedQueries[0] = query.Rewrite(reader1);
			expandedQueries[1] = query.Rewrite(reader2);
			query = query.Combine(expandedQueries);
			
			
			//create an instance of the highlighter with the tags used to surround highlighted text
			Highlighter highlighter = new Highlighter(this, new QueryScorer(query));
			
			for (int i = 0; i < hits.Length(); i++)
			{
				System.String text = hits.Doc(i).Get(FIELD_NAME);
				TokenStream tokenStream = analyzer.TokenStream(FIELD_NAME, new System.IO.StringReader(text));
				System.String highlightedText = highlighter.GetBestFragment(tokenStream, text);
				System.Console.Out.WriteLine(highlightedText);
			}
			Assert.IsTrue(numHighlights == 2, "Failed to find correct number of highlights " + numHighlights + " found");
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:56,代码来源:HighlighterTest.cs


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