Example #1
0
        public void TestSimpleSearch()
        {
            BooleanQuery       bquery;
            SectionSearchQuery squery;
            int count;

            // 1. (+f1:aa +f2:aaa)
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new TermQuery(new Term("f2", "aaa")), Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(4, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count  = GetNumHits(squery, searcher);
            Assert.AreEqual(2, count, "seciton count mismatch");

            // 2. (+f1:bb + f2:aaa)
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "bb")), Occur.MUST);
            bquery.Add(new TermQuery(new Term("f2", "aaa")), Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(4, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count  = GetNumHits(squery, searcher);
            Assert.AreEqual(3, count, "seciton count mismatch");

            // 3. (+f1:aa +f2:bbb)
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new TermQuery(new Term("f2", "bbb")), Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(3, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count  = GetNumHits(squery, searcher);
            Assert.AreEqual(2, count, "seciton count mismatch");

            // 4. (+f1:aa +(f2:bbb f2:ccc))
            BooleanQuery bquery2 = new BooleanQuery();

            bquery2.Add(new TermQuery(new Term("f2", "bbb")), Occur.SHOULD);
            bquery2.Add(new TermQuery(new Term("f2", "ccc")), Occur.SHOULD);
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(bquery2, Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(4, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count  = GetNumHits(squery, searcher);
            Assert.AreEqual(3, count, "section count mismatch");
        }
 public SectionSearchWeight(SectionSearchQuery parent, Searcher searcher)
 {
     _parent = parent;
     _similarity = _parent.GetSimilarity(searcher);
 }
Example #3
0
        private void MetaDataSearch(IndexSearcher searcher)
        {
            IndexReader reader = searcher.IndexReader;

            BooleanQuery       bquery;
            SectionSearchQuery squery;
            Scorer             scorer;
            int count;

            // 1.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(100)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count  = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS)
            {
                count++;
            }
            Assert.AreEqual(1, count, "section count mismatch");

            // 2.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(200)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count  = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS)
            {
                count++;
            }
            Assert.AreEqual(1, count, "section count mismatch");

            // 3.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "bb")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(200)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count  = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS)
            {
                count++;
            }
            Assert.AreEqual(2, count, "section count mismatch");

            // 4.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(300)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count  = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS)
            {
                count++;
            }
            Assert.AreEqual(1, count, "section count mismatch");

            // 5.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "bb")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(300)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count  = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS)
            {
                count++;
            }
            Assert.AreEqual(3, count, "section count mismatch");
        }
 public SectionSearchWeight(SectionSearchQuery parent, IndexSearcher searcher, Query query)
 {
     m_parent = parent;
     m_weight = searcher.CreateNormalizedWeight(query);
 }
        public void TestSimpleSearch()
        {
            BooleanQuery bquery;
            SectionSearchQuery squery;
            int count;

            // 1. (+f1:aa +f2:aaa)
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new TermQuery(new Term("f2", "aaa")), Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(4, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count = GetNumHits(squery, searcher);
            Assert.AreEqual(2, count, "seciton count mismatch");

            // 2. (+f1:bb + f2:aaa)
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "bb")), Occur.MUST);
            bquery.Add(new TermQuery(new Term("f2", "aaa")), Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(4, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count = GetNumHits(squery, searcher);
            Assert.AreEqual(3, count, "seciton count mismatch");

            // 3. (+f1:aa +f2:bbb)
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new TermQuery(new Term("f2", "bbb")), Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(3, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count = GetNumHits(squery, searcher);
            Assert.AreEqual(2, count, "seciton count mismatch");

            // 4. (+f1:aa +(f2:bbb f2:ccc))
            BooleanQuery bquery2 = new BooleanQuery();
            bquery2.Add(new TermQuery(new Term("f2", "bbb")), Occur.SHOULD);
            bquery2.Add(new TermQuery(new Term("f2", "ccc")), Occur.SHOULD);
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(bquery2, Occur.MUST);

            count = GetNumHits(bquery, searcher);
            Assert.AreEqual(4, count, "non-section count mismatch");

            squery = new SectionSearchQuery(bquery);
            count = GetNumHits(squery, searcher);
            Assert.AreEqual(3, count, "section count mismatch");
        }
        private void MetaDataSearch(IndexSearcher searcher)
        {
            IndexReader reader = searcher.IndexReader;

            BooleanQuery bquery;
            SectionSearchQuery squery;
            Scorer scorer;
            int count;

            // 1.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(100)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS) count++;
            Assert.AreEqual(1, count, "section count mismatch");

            // 2.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(200)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS) count++;
            Assert.AreEqual(1, count, "section count mismatch");

            // 3.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "bb")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(200)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS) count++;
            Assert.AreEqual(2, count, "section count mismatch");

            // 4.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "aa")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(300)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS) count++;
            Assert.AreEqual(1, count, "section count mismatch");

            // 5.
            bquery = new BooleanQuery();
            bquery.Add(new TermQuery(new Term("f1", "bb")), Occur.MUST);
            bquery.Add(new IntMetaDataQuery(intMetaTerm, new IntMetaDataQuery.SimpleValueValidator(300)), Occur.MUST);
            squery = new SectionSearchQuery(bquery);
            scorer = squery.CreateWeight(searcher).Scorer(reader, true, true);
            count = 0;
            while (scorer.NextDoc() != Scorer.NO_MORE_DOCS) count++;
            Assert.AreEqual(3, count, "section count mismatch");
        }
Example #7
0
 public SectionSearchWeight(SectionSearchQuery parent, Searcher searcher)
 {
     _parent     = parent;
     _similarity = _parent.GetSimilarity(searcher);
 }