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


C# TermQuery.Weight方法代码示例

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


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

示例1: TestExplain

		public virtual void  TestExplain()
		{
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			Explanation explanation = ts.Explain(0);
			Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
			//System.out.println("Explanation: " + explanation.toString());
			//All this Explain does is return the term frequency
			Assert.IsTrue(explanation.GetValue() == 1, "term frq is not 1");
			explanation = ts.Explain(1);
			Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
			//System.out.println("Explanation: " + explanation.toString());
			//All this Explain does is return the term frequency
			Assert.IsTrue(explanation.GetValue() == 0, "term frq is not 0");
			
			Term dogsTerm = new Term(FIELD, "dogs");
			termQuery = new TermQuery(dogsTerm);
			weight = termQuery.Weight(indexSearcher);
			
			ts = new TermScorer(weight, indexReader.TermDocs(dogsTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			explanation = ts.Explain(1);
			Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
			//System.out.println("Explanation: " + explanation.toString());
			//All this Explain does is return the term frequency
			float sqrtTwo = (float) System.Math.Sqrt(2.0f);
			Assert.IsTrue(explanation.GetValue() == sqrtTwo, "term frq: " + explanation.GetValue() + " is not the square root of 2");
			
			explanation = ts.Explain(10); //try a doc out of range
			Assert.IsTrue(explanation != null, "explanation is null and it shouldn't be");
			//System.out.println("Explanation: " + explanation.toString());
			//All this Explain does is return the term frequency
			
			Assert.IsTrue(explanation.GetValue() == 0, "term frq: " + explanation.GetValue() + " is not 0");
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:38,代码来源:TestTermScorer.cs

示例2: TestSkipTo

		public virtual void  TestSkipTo()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			Assert.IsTrue(ts.Advance(3) != DocIdSetIterator.NO_MORE_DOCS, "Didn't skip");
			//The next doc should be doc 5
			Assert.IsTrue(ts.DocID() == 5, "doc should be number 5");
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:13,代码来源:TestTermScorer.cs

示例3: TestNext

		public virtual void  TestNext()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "next returned a doc and it should not have");
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:15,代码来源:TestTermScorer.cs

示例4: Test

		public virtual void  Test()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			//we have 2 documents with the term all in them, one document for all the other values
			System.Collections.IList docs = new System.Collections.ArrayList();
			//must call next first
			
			
			ts.Score(new AnonymousClassCollector(docs, this));
			Assert.IsTrue(docs.Count == 2, "docs Size: " + docs.Count + " is not: " + 2);
			TestHit doc0 = (TestHit) docs[0];
			TestHit doc5 = (TestHit) docs[1];
			//The scores should be the same
			Assert.IsTrue(doc0.score == doc5.score, doc0.score + " does not equal: " + doc5.score);
			/*
			Score should be (based on Default Sim.:
			All floats are approximate
			tf = 1
			numDocs = 6
			docFreq(all) = 2
			idf = ln(6/3) + 1 = 1.693147
			idf ^ 2 = 2.8667
			boost = 1
			lengthNorm = 1 //there is 1 term in every document
			coord = 1
			sumOfSquaredWeights = (idf * boost) ^ 2 = 1.693147 ^ 2 = 2.8667
			queryNorm = 1 / (sumOfSquaredWeights)^0.5 = 1 /(1.693147) = 0.590
			
			score = 1 * 2.8667 * 1 * 1 * 0.590 = 1.69
			
			*/
			Assert.IsTrue(doc0.score == 1.6931472f, doc0.score + " does not equal: " + 1.6931472f);
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:39,代码来源:TestTermScorer.cs

示例5: TestSkipTo

		public virtual void  TestSkipTo()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			Assert.IsTrue(ts != null, "ts is null and it shouldn't be");
			Assert.IsTrue(ts.SkipTo(3) == true, "Didn't skip");
			//The next doc should be doc 5
			Assert.IsTrue(ts.Doc() == 5, "doc should be number 5");
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:14,代码来源:TestTermScorer.cs

示例6: TestNext

		public virtual void  TestNext()
		{
			
			Term allTerm = new Term(FIELD, "all");
			TermQuery termQuery = new TermQuery(allTerm);
			
			Weight weight = termQuery.Weight(indexSearcher);
			
			TermScorer ts = new TermScorer(weight, indexReader.TermDocs(allTerm), indexSearcher.GetSimilarity(), indexReader.Norms(FIELD));
			Assert.IsTrue(ts != null, "ts is null and it shouldn't be");
			Assert.IsTrue(ts.Next() == true, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.Next() == true, "next did not return a doc");
			Assert.IsTrue(ts.Score() == 1.6931472f, "score is not correct");
			Assert.IsTrue(ts.Next() == false, "next returned a doc and it should not have");
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:16,代码来源:TestTermScorer.cs


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