SOLR-11846: Force BM25Similarity on TestFieldCacheSort.testFieldScoreReverse.

This test expects scores to increase with freq, which not all similarities guarantee.
This commit is contained in:
Adrien Grand 2018-01-11 20:08:14 +01:00
parent 60c6890ff0
commit fa935cf6ac
1 changed files with 3 additions and 0 deletions

View File

@ -50,6 +50,7 @@ import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.similarities.BM25Similarity;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.solr.uninverting.UninvertingReader.Type; import org.apache.solr.uninverting.UninvertingReader.Type;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
@ -434,6 +435,8 @@ public class TestFieldCacheSort extends LuceneTestCase {
writer.close(); writer.close();
IndexSearcher searcher = newSearcher(ir); IndexSearcher searcher = newSearcher(ir);
// this test expects the freq to make doc 1 scores greater than doc 0
searcher.setSimilarity(new BM25Similarity());
Sort sort = new Sort(new SortField(null, SortField.Type.SCORE, true)); Sort sort = new Sort(new SortField(null, SortField.Type.SCORE, true));
TopDocs actual = searcher.search(new TermQuery(new Term("value", "foo")), 10, sort); TopDocs actual = searcher.search(new TermQuery(new Term("value", "foo")), 10, sort);