public virtual void  TestFQ6()
        {
            Query q = new FilteredQuery(qp.Parse("xx"), new ItemizedFilter(new int[] { 1, 3 }));

            q.SetBoost(1000);
            Qtest(q, new int[] { 3 });
        }
Example #2
0
        public virtual void  TestFilteredQuery_Renamed()
        {
            Query filteredquery = new FilteredQuery(query, filter);

            ScoreDoc[] hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
            Assert.AreEqual(1, hits.Length);
            Assert.AreEqual(1, hits[0].doc);
            QueryUtils.Check(filteredquery, searcher);

            hits = searcher.Search(filteredquery, null, 1000, new Sort("sorter")).scoreDocs;
            Assert.AreEqual(1, hits.Length);
            Assert.AreEqual(1, hits[0].doc);

            filteredquery = new FilteredQuery(new TermQuery(new Term("field", "one")), filter);
            hits          = searcher.Search(filteredquery, null, 1000).scoreDocs;
            Assert.AreEqual(2, hits.Length);
            QueryUtils.Check(filteredquery, searcher);

            filteredquery = new FilteredQuery(new TermQuery(new Term("field", "x")), filter);
            hits          = searcher.Search(filteredquery, null, 1000).scoreDocs;
            Assert.AreEqual(1, hits.Length);
            Assert.AreEqual(3, hits[0].doc);
            QueryUtils.Check(filteredquery, searcher);

            filteredquery = new FilteredQuery(new TermQuery(new Term("field", "y")), filter);
            hits          = searcher.Search(filteredquery, null, 1000).scoreDocs;
            Assert.AreEqual(0, hits.Length);
            QueryUtils.Check(filteredquery, searcher);

            // test boost
            Filter f = NewStaticFilterA();

            float        boost = 2.5f;
            BooleanQuery bq1   = new BooleanQuery();
            TermQuery    tq    = new TermQuery(new Term("field", "one"));

            tq.SetBoost(boost);
            bq1.Add(tq, Occur.MUST);
            bq1.Add(new TermQuery(new Term("field", "five")), Occur.MUST);

            BooleanQuery bq2 = new BooleanQuery();

            tq            = new TermQuery(new Term("field", "one"));
            filteredquery = new FilteredQuery(tq, f);
            filteredquery.SetBoost(boost);
            bq2.Add(filteredquery, Occur.MUST);
            bq2.Add(new TermQuery(new Term("field", "five")), Occur.MUST);
            AssertScoreEquals(bq1, bq2);

            Assert.AreEqual(boost, filteredquery.GetBoost(), 0);
            Assert.AreEqual(1.0f, tq.GetBoost(), 0);             // the boost value of the underlying query shouldn't have changed
        }
        public virtual void  Test2()
        {
            BooleanQuery q = new BooleanQuery();

            q.Add(qp.Parse("\"w1 w2\"~1"), Occur.MUST);
            q.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true), Occur.SHOULD);
            q.Add(Snear(Sf("w3", 2), St("w2"), St("w3"), 5, true), Occur.SHOULD);

            Query t = new FilteredQuery(qp.Parse("xx"), new ItemizedFilter(new int[] { 1, 3 }));

            t.SetBoost(1000);
            q.Add(t, Occur.SHOULD);

            t = new ConstantScoreQuery(new ItemizedFilter(new int[] { 0, 2 }));
            t.SetBoost(-20.0f);
            q.Add(t, Occur.SHOULD);

            DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);

            dm.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true));
            dm.Add(qp.Parse("QQ"));
            dm.Add(qp.Parse("xx yy -zz"));
            dm.Add(qp.Parse("-xx -w1"));

            DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);

            dm2.Add(qp.Parse("w1"));
            dm2.Add(qp.Parse("w2"));
            dm2.Add(qp.Parse("w3"));
            dm.Add(dm2);

            q.Add(dm, Occur.SHOULD);

            BooleanQuery b = new BooleanQuery();

            b.SetMinimumNumberShouldMatch(2);
            b.Add(Snear("w1", "w2", 1, true), Occur.SHOULD);
            b.Add(Snear("w2", "w3", 1, true), Occur.SHOULD);
            b.Add(Snear("w1", "w3", 3, true), Occur.SHOULD);
            b.SetBoost(0.0f);

            q.Add(b, Occur.SHOULD);

            Qtest(q, new int[] { 0, 1, 2 });
        }
		public virtual void  Test1()
		{
			
			BooleanQuery q = new BooleanQuery();
			
			q.Add(qp.Parse("\"w1 w2\"~1"), Occur.MUST);
			q.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true), Occur.SHOULD);
			q.Add(Snear(Sf("w3", 2), St("w2"), St("w3"), 5, true), Occur.SHOULD);
			
			Query t = new FilteredQuery(qp.Parse("xx"), new ItemizedFilter(new int[]{1, 3}));
			t.SetBoost(1000);
			q.Add(t, Occur.SHOULD);
			
			t = new ConstantScoreQuery(new ItemizedFilter(new int[]{0, 2}));
			t.SetBoost(30);
			q.Add(t, Occur.SHOULD);
			
			DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
			dm.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true));
			dm.Add(qp.Parse("QQ"));
			dm.Add(qp.Parse("xx yy -zz"));
			dm.Add(qp.Parse("-xx -w1"));
			
			DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
			dm2.Add(qp.Parse("w1"));
			dm2.Add(qp.Parse("w2"));
			dm2.Add(qp.Parse("w3"));
			dm.Add(dm2);
			
			q.Add(dm, Occur.SHOULD);
			
			BooleanQuery b = new BooleanQuery();
			b.SetMinimumNumberShouldMatch(2);
			b.Add(Snear("w1", "w2", 1, true), Occur.SHOULD);
			b.Add(Snear("w2", "w3", 1, true), Occur.SHOULD);
			b.Add(Snear("w1", "w3", 3, true), Occur.SHOULD);
			
			q.Add(b, Occur.SHOULD);
			
			Qtest(q, new int[]{0, 1, 2});
		}
		public virtual void  TestFQ6()
		{
			Query q = new FilteredQuery(qp.Parse("xx"), new ItemizedFilter(new int[]{1, 3}));
			q.SetBoost(1000);
			Qtest(q, new int[]{3});
		}
Example #6
0
		public virtual void  TestFilteredQuery_Renamed()
		{
			Query filteredquery = new FilteredQuery(query, filter);
			ScoreDoc[] hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(1, hits.Length);
			Assert.AreEqual(1, hits[0].doc);
			QueryUtils.Check(filteredquery, searcher);
			
			hits = searcher.Search(filteredquery, null, 1000, new Sort("sorter")).scoreDocs;
			Assert.AreEqual(1, hits.Length);
			Assert.AreEqual(1, hits[0].doc);
			
			filteredquery = new FilteredQuery(new TermQuery(new Term("field", "one")), filter);
			hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(2, hits.Length);
			QueryUtils.Check(filteredquery, searcher);
			
			filteredquery = new FilteredQuery(new TermQuery(new Term("field", "x")), filter);
			hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(1, hits.Length);
			Assert.AreEqual(3, hits[0].doc);
			QueryUtils.Check(filteredquery, searcher);
			
			filteredquery = new FilteredQuery(new TermQuery(new Term("field", "y")), filter);
			hits = searcher.Search(filteredquery, null, 1000).scoreDocs;
			Assert.AreEqual(0, hits.Length);
			QueryUtils.Check(filteredquery, searcher);
			
			// test boost
			Filter f = NewStaticFilterA();
			
			float boost = 2.5f;
			BooleanQuery bq1 = new BooleanQuery();
			TermQuery tq = new TermQuery(new Term("field", "one"));
			tq.SetBoost(boost);
			bq1.Add(tq, Occur.MUST);
			bq1.Add(new TermQuery(new Term("field", "five")), Occur.MUST);
			
			BooleanQuery bq2 = new BooleanQuery();
			tq = new TermQuery(new Term("field", "one"));
			filteredquery = new FilteredQuery(tq, f);
			filteredquery.SetBoost(boost);
			bq2.Add(filteredquery, Occur.MUST);
			bq2.Add(new TermQuery(new Term("field", "five")), Occur.MUST);
			AssertScoreEquals(bq1, bq2);
			
			Assert.AreEqual(boost, filteredquery.GetBoost(), 0);
			Assert.AreEqual(1.0f, tq.GetBoost(), 0); // the boost value of the underlying query shouldn't have changed 
		}