The BoostingQuery class can be used to effectively demote results that match a given query. Unlike the "NOT" clause, this still selects documents that contain undesirable terms, but reduces their overall score:
 Query balancedQuery = new BoostingQuery(positiveQuery, negativeQuery, 0.01f); 
In this scenario the positiveQuery contains the mandatory, desirable criteria which is used to select all matching documents, and the negativeQuery contains the undesirable elements which are simply used to lessen the scores. Documents that match the negativeQuery have their score multiplied by the supplied "boost" parameter, so this should be less than 1 to achieve a demoting effect This code was originally made available here: mailing list and is documented here: Documentation
상속: Query
예제 #1
0
 public void TestBoostingQueryEquals()
 {
     TermQuery q1 = new TermQuery(new Term("subject:", "java"));
     TermQuery q2 = new TermQuery(new Term("subject:", "java"));
     Assert.AreEqual(q1, q2, "Two TermQueries with same attributes should be equal");
     BoostingQuery bq1 = new BoostingQuery(q1, q2, 0.1f);
     BoostingQuery bq2 = new BoostingQuery(q1, q2, 0.1f);
     Assert.AreEqual(bq1, bq2, "BoostingQuery with same attributes is not equal");
 }
예제 #2
0
        public void TestBoostingQueryEquals()
        {
            TermQuery q1 = new TermQuery(new Term("subject:", "java"));
            TermQuery q2 = new TermQuery(new Term("subject:", "java"));

            Assert.AreEqual(q1, q2, "Two TermQueries with same attributes should be equal");
            BoostingQuery bq1 = new BoostingQuery(q1, q2, 0.1f);
            BoostingQuery bq2 = new BoostingQuery(q1, q2, 0.1f);

            Assert.AreEqual(bq1, bq2, "BoostingQuery with same attributes is not equal");
        }
예제 #3
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            BoostingQuery other = (BoostingQuery)obj;

            if (BitConverter.ToInt32(BitConverter.GetBytes(boost), 0) != BitConverter.ToInt32(BitConverter.GetBytes(other.boost), 0))
            {
                return(false);
            }
            if (context == null)
            {
                if (other.context != null)
                {
                    return(false);
                }
            }
            else if (!context.Equals(other.context))
            {
                return(false);
            }
            if (match == null)
            {
                if (other.match != null)
                {
                    return(false);
                }
            }
            else if (!match.Equals(other.match))
            {
                return(false);
            }
            return(true);
        }