本文整理汇总了C#中Lucene.Net.Search.TermRangeQuery.GetTotalNumberOfTerms方法的典型用法代码示例。如果您正苦于以下问题:C# TermRangeQuery.GetTotalNumberOfTerms方法的具体用法?C# TermRangeQuery.GetTotalNumberOfTerms怎么用?C# TermRangeQuery.GetTotalNumberOfTerms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.TermRangeQuery
的用法示例。
在下文中一共展示了TermRangeQuery.GetTotalNumberOfTerms方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRandomTrieAndClassicRangeQuery
private void TestRandomTrieAndClassicRangeQuery(int precisionStep)
{
System.Random rnd = NewRandom();
System.String field = "field" + precisionStep;
int termCountT = 0, termCountC = 0;
for (int i = 0; i < 50; i++)
{
long lower = (long) (rnd.NextDouble() * noDocs * distance) + startOffset;
long upper = (long) (rnd.NextDouble() * noDocs * distance) + startOffset;
if (lower > upper)
{
long a = lower; lower = upper; upper = a;
}
// test inclusive range
System.Int64 tempAux = (long) lower;
System.Int64 tempAux2 = (long) upper;
NumericRangeQuery tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);
TermRangeQuery cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), true, true);
TopDocs tTopDocs = searcher.Search(tq, 1);
TopDocs cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
// test exclusive range
System.Int64 tempAux3 = (long) lower;
System.Int64 tempAux4 = (long) upper;
tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux3, tempAux4, false, false);
cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), false, false);
tTopDocs = searcher.Search(tq, 1);
cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
// test left exclusive range
System.Int64 tempAux5 = (long) lower;
System.Int64 tempAux6 = (long) upper;
tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux5, tempAux6, false, true);
cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), false, true);
tTopDocs = searcher.Search(tq, 1);
cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
// test right exclusive range
System.Int64 tempAux7 = (long) lower;
System.Int64 tempAux8 = (long) upper;
tq = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux7, tempAux8, true, false);
cq = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), true, false);
tTopDocs = searcher.Search(tq, 1);
cTopDocs = searcher.Search(cq, 1);
Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
termCountT += tq.GetTotalNumberOfTerms();
termCountC += cq.GetTotalNumberOfTerms();
}
if (precisionStep == System.Int32.MaxValue)
{
Assert.AreEqual(termCountT, termCountC, "Total number of terms should be equal for unlimited precStep");
}
else
{
System.Console.Out.WriteLine("Average number of terms during random search on '" + field + "':");
System.Console.Out.WriteLine(" Trie query: " + (((double) termCountT) / (50 * 4)));
System.Console.Out.WriteLine(" Classical query: " + (((double) termCountC) / (50 * 4)));
}
}