public static CheckEqual ( |
||
query | ||
hits1 | Lucene.Net.Search.ScoreDoc | |
hits2 | Lucene.Net.Search.ScoreDoc | |
return | void |
/// <summary> /// check that the # of hits is the same as from a very /// simple prefixquery implementation. /// </summary> private void AssertSame(string prefix) { PrefixQuery smart = new PrefixQuery(new Term("field", prefix)); DumbPrefixQuery dumb = new DumbPrefixQuery(this, new Term("field", prefix)); TopDocs smartDocs = Searcher.Search(smart, 25); TopDocs dumbDocs = Searcher.Search(dumb, 25); CheckHits.CheckEqual(smart, smartDocs.ScoreDocs, dumbDocs.ScoreDocs); }
/// <summary> /// check that the # of hits is the same as from a very /// simple regexpquery implementation. /// </summary> protected internal virtual void AssertSame(string regexp) { RegexpQuery smart = new RegexpQuery(new Term(FieldName, regexp), RegExp.NONE); DumbRegexpQuery dumb = new DumbRegexpQuery(this, new Term(FieldName, regexp), RegExp.NONE); TopDocs smartDocs = Searcher1.Search(smart, 25); TopDocs dumbDocs = Searcher2.Search(dumb, 25); CheckHits.CheckEqual(smart, smartDocs.ScoreDocs, dumbDocs.ScoreDocs); }
/// <summary> /// check that the # of hits is the same as if the query /// is run against the inverted index /// </summary> protected internal virtual void AssertSame(string regexp) { RegexpQuery docValues = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE); docValues.MultiTermRewriteMethod = (new DocTermOrdsRewriteMethod()); RegexpQuery inverted = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE); TopDocs invertedDocs = searcher1.Search(inverted, 25); TopDocs docValuesDocs = searcher2.Search(docValues, 25); CheckHits.CheckEqual(inverted, invertedDocs.ScoreDocs, docValuesDocs.ScoreDocs); }
/// <summary> /// check that the # of hits is the same as if the query /// is run against the inverted index /// </summary> protected internal virtual void AssertSame(BytesRef lowerVal, BytesRef upperVal, bool includeLower, bool includeUpper) { Query docValues = new ConstantScoreQuery(DocTermOrdsRangeFilter.NewBytesRefRange(fieldName, lowerVal, upperVal, includeLower, includeUpper)); MultiTermQuery inverted = new TermRangeQuery(fieldName, lowerVal, upperVal, includeLower, includeUpper); inverted.MultiTermRewriteMethod = (MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); TopDocs invertedDocs = searcher1.Search(inverted, 25); TopDocs docValuesDocs = searcher2.Search(docValues, 25); CheckHits.CheckEqual(inverted, invertedDocs.ScoreDocs, docValuesDocs.ScoreDocs); }
public virtual void TestRandomQueries() { System.Random rnd = NewRandom(); System.String[] vals = new System.String[] { "w1", "w2", "w3", "w4", "w5", "xx", "yy", "zzz" }; int tot = 0; BooleanQuery q1 = null; try { // increase number of iterations for more complete testing for (int i = 0; i < 1000; i++) { int level = rnd.Next(3); q1 = RandBoolQuery(new System.Random(rnd.Next(System.Int32.MaxValue)), rnd.Next(0, 2) == 0 ? false : true, level, field, vals, null); // Can't sort by relevance since floating point numbers may not quite // match up. Sort sort = Sort.INDEXORDER; QueryUtils.Check(q1, searcher); TopFieldCollector collector = TopFieldCollector.Create(sort, 1000, false, true, true, true); searcher.Search(q1, null, collector, null); ScoreDoc[] hits1 = collector.TopDocs().ScoreDocs; collector = TopFieldCollector.Create(sort, 1000, false, true, true, false); searcher.Search(q1, null, collector, null); ScoreDoc[] hits2 = collector.TopDocs().ScoreDocs; tot += hits2.Length; CheckHits.CheckEqual(q1, hits1, hits2); BooleanQuery q3 = new BooleanQuery(); q3.Add(q1, Occur.SHOULD); q3.Add(new PrefixQuery(new Term("field2", "b")), Occur.SHOULD); TopDocs hits4 = bigSearcher.Search(q3, 1, null); Assert.AreEqual(mulFactor * collector.internalTotalHits + NUM_EXTRA_DOCS / 2, hits4.TotalHits); } } catch (System.Exception e) { // For easier debugging System.Console.Out.WriteLine("failed query: " + q1); throw e; } // System.out.println("Total hits:"+tot); }
private void AssertFilterEquals(Filter f1, Filter f2) { Query query = new MatchAllDocsQuery(); TopDocs hits1 = @is.Search(query, f1, ir.MaxDoc); TopDocs hits2 = @is.Search(query, f2, ir.MaxDoc); Assert.AreEqual(hits1.TotalHits, hits2.TotalHits); CheckHits.CheckEqual(query, hits1.ScoreDocs, hits2.ScoreDocs); // now do it again to confirm caching works TopDocs hits3 = @is.Search(query, f1, ir.MaxDoc); TopDocs hits4 = @is.Search(query, f2, ir.MaxDoc); Assert.AreEqual(hits3.TotalHits, hits4.TotalHits); CheckHits.CheckEqual(query, hits3.ScoreDocs, hits4.ScoreDocs); }
/// <summary> /// Test fieldcache rewrite against filter rewrite </summary> protected internal override void AssertSame(string regexp) { RegexpQuery fieldCache = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE); fieldCache.MultiTermRewriteMethod = (new FieldCacheRewriteMethod()); RegexpQuery filter = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE); filter.MultiTermRewriteMethod = (MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); TopDocs fieldCacheDocs = searcher1.Search(fieldCache, 25); TopDocs filterDocs = searcher2.Search(filter, 25); CheckHits.CheckEqual(fieldCache, fieldCacheDocs.ScoreDocs, filterDocs.ScoreDocs); }
public virtual void TestRandomQueries() { System.Random rnd = NewRandom(); System.String[] vals = new System.String[] { "w1", "w2", "w3", "w4", "w5", "xx", "yy", "zzz" }; int tot = 0; BooleanQuery q1 = null; try { // increase number of iterations for more complete testing for (int i = 0; i < 1000; i++) { int level = rnd.Next(3); q1 = RandBoolQuery(new System.Random((System.Int32)rnd.Next(System.Int32.MaxValue)), level, field, vals, null); // Can't sort by relevance since floating point numbers may not quite // match up. Sort sort = Sort.INDEXORDER; BooleanQuery.SetAllowDocsOutOfOrder(false); QueryUtils.Check(q1, searcher); ScoreDoc[] hits1 = searcher.Search(q1, null, 1000, sort).scoreDocs; BooleanQuery.SetAllowDocsOutOfOrder(true); ScoreDoc[] hits2 = searcher.Search(q1, null, 1000, sort).scoreDocs; tot += hits2.Length; CheckHits.CheckEqual(q1, hits1, hits2); } } catch (System.Exception e) { // For easier debugging System.Console.Out.WriteLine("failed query: " + q1); throw e; } finally { // even when a test fails. BooleanQuery.SetAllowDocsOutOfOrder(false); } // System.out.println("Total hits:"+tot); }
public virtual void TestRandomQueries() { string[] vals = new string[] { "w1", "w2", "w3", "w4", "w5", "xx", "yy", "zzz" }; int tot = 0; BooleanQuery q1 = null; try { // increase number of iterations for more complete testing int num = AtLeast(20); for (int i = 0; i < num; i++) { int level = Random.Next(3); q1 = RandBoolQuery(new Random(Random.Next()), Random.NextBoolean(), level, field, vals, null); // Can't sort by relevance since floating point numbers may not quite // match up. Sort sort = Sort.INDEXORDER; QueryUtils.Check( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, q1, Searcher); // baseline sim try { // a little hackish, QueryUtils.check is too costly to do on bigSearcher in this loop. Searcher.Similarity = BigSearcher.Similarity; // random sim QueryUtils.Check( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, q1, Searcher); } finally { Searcher.Similarity = new DefaultSimilarity(); // restore } TopFieldCollector collector = TopFieldCollector.Create(sort, 1000, false, true, true, true); Searcher.Search(q1, null, collector); ScoreDoc[] hits1 = collector.GetTopDocs().ScoreDocs; collector = TopFieldCollector.Create(sort, 1000, false, true, true, false); Searcher.Search(q1, null, collector); ScoreDoc[] hits2 = collector.GetTopDocs().ScoreDocs; tot += hits2.Length; CheckHits.CheckEqual(q1, hits1, hits2); BooleanQuery q3 = new BooleanQuery(); q3.Add(q1, Occur.SHOULD); q3.Add(new PrefixQuery(new Term("field2", "b")), Occur.SHOULD); TopDocs hits4 = BigSearcher.Search(q3, 1); Assert.AreEqual(MulFactor * collector.TotalHits + NUM_EXTRA_DOCS / 2, hits4.TotalHits); } } catch (Exception) { // For easier debugging Console.WriteLine("failed query: " + q1); throw; } // System.out.println("Total hits:"+tot); }
public virtual void TestRandomQueries() { string[] vals = new string[] { "w1", "w2", "w3", "w4", "w5", "xx", "yy", "zzz" }; int tot = 0; BooleanQuery q1 = null; try { // increase number of iterations for more complete testing int num = AtLeast(20); for (int i = 0; i < num; i++) { int level = Random.Next(3); q1 = RandBoolQuery(new J2N.Randomizer(Random.NextInt64()), Random.NextBoolean(), level, field, vals, null); // Can't sort by relevance since floating point numbers may not quite // match up. Sort sort = Sort.INDEXORDER; QueryUtils.Check(Random, q1, searcher); // baseline sim try { // a little hackish, QueryUtils.check is too costly to do on bigSearcher in this loop. searcher.Similarity = bigSearcher.Similarity; // random sim QueryUtils.Check(Random, q1, searcher); } finally { searcher.Similarity = new DefaultSimilarity(); // restore } TopFieldCollector collector = TopFieldCollector.Create(sort, 1000, false, true, true, true); searcher.Search(q1, null, collector); ScoreDoc[] hits1 = collector.GetTopDocs().ScoreDocs; collector = TopFieldCollector.Create(sort, 1000, false, true, true, false); searcher.Search(q1, null, collector); ScoreDoc[] hits2 = collector.GetTopDocs().ScoreDocs; tot += hits2.Length; CheckHits.CheckEqual(q1, hits1, hits2); BooleanQuery q3 = new BooleanQuery(); q3.Add(q1, Occur.SHOULD); q3.Add(new PrefixQuery(new Term("field2", "b")), Occur.SHOULD); TopDocs hits4 = bigSearcher.Search(q3, 1); Assert.AreEqual(mulFactor * collector.TotalHits + NUM_EXTRA_DOCS / 2, hits4.TotalHits); } } catch (Exception e) when(e.IsException()) { // For easier debugging Console.WriteLine("failed query: " + q1); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) } // System.out.println("Total hits:"+tot); }