示例#1
0
        private void CheckEqualParsings(string s1, string s2)
        {
            string            fieldName = "foo";
            BasicQueryFactory qf        = new BasicQueryFactory(16);

            Search.Query lq1, lq2;
            lq1 = Parser.QueryParser.Parse(s1).MakeLuceneQueryField(fieldName, qf);
            lq2 = Parser.QueryParser.Parse(s2).MakeLuceneQueryField(fieldName, qf);
            QueryUtils.CheckEqual(lq1, lq2);
        }
        public virtual void TestRewrite2()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("last", "smith"));
            SpanQuery q2 = new SpanTermQuery(new Term("last", "jones"));
            SpanQuery q  = new SpanNearQuery(new SpanQuery[] { q1, new FieldMaskingSpanQuery(q2, "last") }, 1, true);
            Query     qr = Searcher.Rewrite(q);

            QueryUtils.CheckEqual(q, qr);

            HashSet <Term> set = new HashSet <Term>();

            qr.ExtractTerms(set);
            Assert.AreEqual(2, set.Count);
        }
        public virtual void TestRewrite0()
        {
            SpanQuery q = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "first");

            q.Boost = 8.7654321f;
            SpanQuery qr = (SpanQuery)Searcher.Rewrite(q);

            QueryUtils.CheckEqual(q, qr);

            HashSet <Term> terms = new HashSet <Term>();

            qr.ExtractTerms(terms);
            Assert.AreEqual(1, terms.Count);
        }
        public virtual void  TestRewrite2()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("last", "smith"));
            SpanQuery q2 = new SpanTermQuery(new Term("last", "jones"));
            SpanQuery q  = new SpanNearQuery(new SpanQuery[] { q1, new FieldMaskingSpanQuery(q2, "last") }, 1, true);
            Query     qr = searcher.Rewrite(q);

            QueryUtils.CheckEqual(q, qr);

            var set_Renamed = Support.Compatibility.SetFactory.CreateHashSet <Term>();

            qr.ExtractTerms(set_Renamed);
            Assert.AreEqual(2, set_Renamed.Count);
        }
        public virtual void  TestRewrite0()
        {
            SpanQuery q = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "first");

            q.Boost = 8.7654321f;
            SpanQuery qr = (SpanQuery)searcher.Rewrite(q);

            QueryUtils.CheckEqual(q, qr);

            var terms = Support.Compatibility.SetFactory.CreateHashSet <Term>();

            qr.ExtractTerms(terms);
            Assert.AreEqual(1, terms.Count);
        }
示例#6
0
        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);
        }