br.setQuery(parser.parse("color:red OR shape:square"));
br.setCount(10);
br.setOffset(0);
br.setSort(new SortField[] { SortField.FIELD_SCORE });
BrowseResult res = doTest(br, 4, null, new String[] { "1", "7", "2", "5" });
BrowseHit[] hits = res.getHits();
for (BrowseHit hit : hits) {
assertNull(hit.getExplanation());
}
br.setShowExplanation(true);
res = doTest(br, 4, null, new String[] { "1", "7", "2", "5" });
hits = res.getHits();
for (BrowseHit hit : hits) {
assertNotNull(hit.getExplanation());
}
Query rawQuery = br.getQuery();
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
Date d = format.parse("2006/06/01");
long fromTime = d.getTime();
RecencyBoostScorerBuilder recencyBuilder = new RecencyBoostScorerBuilder("date", 2.0f,
TimeUnit.DAYS.convert(fromTime, TimeUnit.MILLISECONDS), 30L, TimeUnit.DAYS);
ScoreAdjusterQuery sq = new ScoreAdjusterQuery(rawQuery, recencyBuilder);
br.setQuery(sq);
res = doTest(br, 4, null, new String[] { "7", "1", "2", "5" });
hits = res.getHits();
for (BrowseHit hit : hits) {
assertNotNull(hit.getExplanation());
System.out.println(hit.getExplanation());
}
}