public virtual void TestRewrite1() { // mask an anon SpanQuery class that rewrites to something else. SpanQuery q = new FieldMaskingSpanQuery(new SpanTermQueryAnonymousInnerClassHelper(this, new Term("last", "sally")), "first"); SpanQuery qr = (SpanQuery)Searcher.Rewrite(q); QueryUtils.CheckUnequal(q, qr); HashSet <Term> terms = new HashSet <Term>(); qr.ExtractTerms(terms); Assert.AreEqual(2, terms.Count); }
public virtual void TestQuery() { PayloadTermQuery boostingFuncTermQuery = new PayloadTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"), new MaxPayloadFunction()); QueryUtils.Check(boostingFuncTermQuery); SpanTermQuery spanTermQuery = new SpanTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy")); Assert.IsTrue(boostingFuncTermQuery.Equals(spanTermQuery) == spanTermQuery.Equals(boostingFuncTermQuery)); PayloadTermQuery boostingFuncTermQuery2 = new PayloadTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"), new AveragePayloadFunction()); QueryUtils.CheckUnequal(boostingFuncTermQuery, boostingFuncTermQuery2); }
public virtual void TestRewrite1() { // mask an anon SpanQuery class that rewrites to something else. SpanQuery q = new FieldMaskingSpanQuery(new AnonymousClassSpanTermQuery(this, new Term("last", "sally")), "first"); SpanQuery qr = (SpanQuery)searcher.Rewrite(q); QueryUtils.CheckUnequal(q, qr); var terms = Support.Compatibility.SetFactory.CreateHashSet <Term>(); qr.ExtractTerms(terms); Assert.AreEqual(2, terms.Count); }
public virtual void TestSpanNearExact() { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "seventy")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "seven")); SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { term1, term2 }, 0, true); CheckHits(query, new int[] { 77, 177, 277, 377, 477, 577, 677, 777, 877, 977, 1077, 1177, 1277, 1377, 1477, 1577, 1677, 1777, 1877, 1977 }); Assert.IsTrue(Searcher.Explain(query, 77).Value > 0.0f); Assert.IsTrue(Searcher.Explain(query, 977).Value > 0.0f); QueryUtils.Check(term1); QueryUtils.Check(term2); QueryUtils.CheckUnequal(term1, term2); }
public void TestEqualsHashCode() { CommonTermsQuery query = new CommonTermsQuery(RandomOccur(Random), RandomOccur(Random), Random.NextSingle(), Random.NextBoolean()); int terms = AtLeast(2); for (int i = 0; i < terms; i++) { query.Add(new Term(TestUtil.RandomRealisticUnicodeString(Random), TestUtil.RandomRealisticUnicodeString(Random))); } QueryUtils.CheckHashEquals(query); QueryUtils.CheckUnequal(new CommonTermsQuery(RandomOccur(Random), RandomOccur(Random), Random.NextSingle(), Random.NextBoolean()), query); { long seed = Random.NextInt64(); Random r = new Random((int)seed); CommonTermsQuery left = new CommonTermsQuery(RandomOccur(r), RandomOccur(r), r.NextSingle(), r.NextBoolean()); int leftTerms = AtLeast(r, 2); for (int i = 0; i < leftTerms; i++) { left.Add(new Term(TestUtil.RandomRealisticUnicodeString(r), TestUtil.RandomRealisticUnicodeString(r))); } left.HighFreqMinimumNumberShouldMatch = r.nextInt(4); left.LowFreqMinimumNumberShouldMatch = r.nextInt(4); r = new Random((int)seed); CommonTermsQuery right = new CommonTermsQuery(RandomOccur(r), RandomOccur(r), r.NextSingle(), r.NextBoolean()); int rightTerms = AtLeast(r, 2); for (int i = 0; i < rightTerms; i++) { right.Add(new Term(TestUtil.RandomRealisticUnicodeString(r), TestUtil.RandomRealisticUnicodeString(r))); } right.HighFreqMinimumNumberShouldMatch = r.nextInt(4); right.LowFreqMinimumNumberShouldMatch = r.nextInt(4); QueryUtils.CheckEqual(left, right); } }
public virtual void TestEquality1() { SpanQuery q1 = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "first"); SpanQuery q2 = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "first"); SpanQuery q3 = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "XXXXX"); SpanQuery q4 = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "XXXXX")), "first"); SpanQuery q5 = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("xXXX", "sally")), "first"); QueryUtils.CheckEqual(q1, q2); QueryUtils.CheckUnequal(q1, q3); QueryUtils.CheckUnequal(q1, q4); QueryUtils.CheckUnequal(q1, q5); SpanQuery qA = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "first"); qA.Boost = 9f; SpanQuery qB = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "first"); QueryUtils.CheckUnequal(qA, qB); qB.Boost = 9f; QueryUtils.CheckEqual(qA, qB); }