Boosting a clause (SHOULD)
We’ll do that again, but we will give a boost to documents that are multiples of 7. So, most
of the matches will have score 2.0, but 70, 140, 280, etc. will have score 3.0. (We skip 210 because
it’s a multiple of 3.)
BooleanQuery twoAndFiveNotThreeMaybeSeven = new BooleanQuery.Builder()
.add(new TermQuery(new Term("text", "two")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term("text", "five")), BooleanClause.Occur.MUST)
.add(new TermQuery(new Term("text", "three")), BooleanClause.Occur.MUST_NOT)
.add(new TermQuery(new Term("text", "seven")), BooleanClause.Occur.SHOULD)
.build();
System.out.println(twoAndFiveNotThreeMaybeSeven.toString());
outputSearchResultsAndScores(searcher, twoAndFiveNotThreeMaybeSeven);