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);
|
return 0x45aaf665 + Arrays.hashCode(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether the relevance score is needed to sort documents. */
|
/** Returns true if the relevance score is needed to sort documents. */
|
||||||
boolean needsScores() {
|
public boolean needsScores() {
|
||||||
for (SortField sortField : fields) {
|
for (SortField sortField : fields) {
|
||||||
if (sortField.needsScores()) {
|
if (sortField.needsScores()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -39,6 +39,9 @@ final class Sorter {
|
||||||
|
|
||||||
/** Creates a new Sorter to sort the index with {@code sort} */
|
/** Creates a new Sorter to sort the index with {@code sort} */
|
||||||
Sorter(Sort 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;
|
this.sort = sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,4 +63,13 @@ public class SortingAtomicReaderTest extends SorterTestBase {
|
||||||
TestUtil.checkReader(reader);
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,4 +173,13 @@ public class TestSortingMergePolicy extends LuceneTestCase {
|
||||||
assertReaderEquals("", sortedReader1, sortedReader2);
|
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