mirror of https://github.com/apache/lucene.git
LUCENE-5500: SortingMergePolicy should error if the Sort refers to the score
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1575306 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b87af54774
commit
55edc565d8
|
@ -202,8 +202,8 @@ public class Sort {
|
|||
return 0x45aaf665 + Arrays.hashCode(fields);
|
||||
}
|
||||
|
||||
/** Whether the relevance score is needed to sort documents. */
|
||||
boolean needsScores() {
|
||||
/** Returns true if the relevance score is needed to sort documents. */
|
||||
public boolean needsScores() {
|
||||
for (SortField sortField : fields) {
|
||||
if (sortField.needsScores()) {
|
||||
return true;
|
||||
|
|
|
@ -39,6 +39,9 @@ final class Sorter {
|
|||
|
||||
/** Creates a new Sorter to sort the index with {@code sort} */
|
||||
Sorter(Sort sort) {
|
||||
if (sort.needsScores()) {
|
||||
throw new IllegalArgumentException("Cannot sort an index with a Sort that refers to the relevance score");
|
||||
}
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,5 +62,14 @@ public class SortingAtomicReaderTest extends SorterTestBase {
|
|||
|
||||
TestUtil.checkReader(reader);
|
||||
}
|
||||
|
||||
public void testBadSort() throws Exception {
|
||||
try {
|
||||
SortingAtomicReader.wrap(reader, Sort.RELEVANCE);
|
||||
fail("Didn't get expected exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Cannot sort an index with a Sort that refers to the relevance score", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -172,5 +172,14 @@ public class TestSortingMergePolicy extends LuceneTestCase {
|
|||
|
||||
assertReaderEquals("", sortedReader1, sortedReader2);
|
||||
}
|
||||
|
||||
public void testBadSort() throws Exception {
|
||||
try {
|
||||
new SortingMergePolicy(newMergePolicy(), Sort.RELEVANCE);
|
||||
fail("Didn't get expected exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Cannot sort an index with a Sort that refers to the relevance score", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue