public virtual void TestBooleanOptionalWithTiebreaker()
{
BooleanQuery q = new BooleanQuery();
{
DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.01f);
q1.Add(Tq("hed", "albino"));
q1.Add(Tq("dek", "albino"));
q.Add(q1, BooleanClause.Occur.SHOULD); // false,false);
}
{
DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.01f);
q2.Add(Tq("hed", "elephant"));
q2.Add(Tq("dek", "elephant"));
q.Add(q2, BooleanClause.Occur.SHOULD); // false,false);
}
QueryUtils.Check(Random(), q, s, Similarity);
ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;
try
{
Assert.AreEqual(4, h.Length, "4 docs should match " + q.ToString());
float score0 = h[0].Score;
float score1 = h[1].Score;
float score2 = h[2].Score;
float score3 = h[3].Score;
string doc0 = s.Doc(h[0].Doc).Get("id");
string doc1 = s.Doc(h[1].Doc).Get("id");
string doc2 = s.Doc(h[2].Doc).Get("id");
string doc3 = s.Doc(h[3].Doc).Get("id");
Assert.IsTrue(doc0.Equals("d2") || doc0.Equals("d4"), "doc0 should be d2 or d4: " + doc0);
Assert.IsTrue(doc1.Equals("d2") || doc1.Equals("d4"), "doc1 should be d2 or d4: " + doc0);
Assert.AreEqual(score0, score1, SCORE_COMP_THRESH, "score0 and score1 should match");
Assert.AreEqual("d3", doc2, "wrong third");
Assert.IsTrue(score1 > score2, "d3 does not have worse score then d2 and d4: " + score1 + " >? " + score2);
Assert.AreEqual("d1", doc3, "wrong fourth");
Assert.IsTrue(score2 > score3, "d1 does not have worse score then d3: " + score2 + " >? " + score3);
}
catch (Exception e)
{
PrintHits("testBooleanOptionalWithTiebreaker", h, s);
throw e;
}
}