Fix test to stop asserting specific order when secondary sort is unspecified, add new checks that do assert an explicit order when secondary sort IS specified.

This commit is contained in:
Chris Hostetter 2017-03-23 18:28:10 -07:00
parent c221ef0fde
commit 6665aed952
1 changed files with 95 additions and 13 deletions

View File

@ -51,12 +51,15 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
public void testSortMissingFirstLast() { public void testSortMissingFirstLast() {
clearIndex(); clearIndex();
// NOTE: segments may be merged in any order, so we can't make any assumptions about
// the relative order of M1 vs M2 unless we have a secondary sort
assertU(adoc("id", "M1")); assertU(adoc("id", "M1"));
assertU(adoc(getDoc("+4", 4, "2011-04-04T00:00:00Z"))); assertU(adoc(getDoc("+4", 4, "2011-04-04T00:00:00Z")));
assertU(adoc(getDoc("+5", 5, "2011-05-05T00:00:00Z"))); assertU(adoc(getDoc("+5", 5, "2011-05-05T00:00:00Z")));
assertU(adoc(getDoc("-3", -3, "2011-01-01T00:00:00Z"))); assertU(adoc(getDoc("-3", -3, "2011-01-01T00:00:00Z")));
assertU(adoc("id", "M2")); assertU(adoc("id", "M2"));
assertU(commit()); assertU(commit());
// 'normal' sorting. Missing Values are 0 // 'normal' sorting. Missing Values are 0
String suffix = ""; String suffix = "";
for (String t : types) { for (String t : types) {
@ -64,8 +67,8 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
assertQ("Sorting Asc: " + t + suffix, assertQ("Sorting Asc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"), req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),
"//*[@numFound='5']", "//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='M1']", "//result/doc[1]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[2]/str[@name='id'][.='M2']", "//result/doc[2]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[3]/str[@name='id'][.='-3']", "//result/doc[3]/str[@name='id'][.='-3']",
"//result/doc[4]/str[@name='id'][.='+4']", "//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='+5']" "//result/doc[5]/str[@name='id'][.='+5']"
@ -77,6 +80,26 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
"//result/doc[1]/str[@name='id'][.='+5']", "//result/doc[1]/str[@name='id'][.='+5']",
"//result/doc[2]/str[@name='id'][.='+4']", "//result/doc[2]/str[@name='id'][.='+4']",
"//result/doc[3]/str[@name='id'][.='-3']", "//result/doc[3]/str[@name='id'][.='-3']",
"//result/doc[4]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[5]/str[@name='id'][starts-with(.,'M')]"
);
assertQ("Sorting Asc w/secondary on id desc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc, id desc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='M2']",
"//result/doc[2]/str[@name='id'][.='M1']",
"//result/doc[3]/str[@name='id'][.='-3']",
"//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='+5']"
);
assertQ("Sorting Desc w/secondary on id asc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc, id asc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='+5']",
"//result/doc[2]/str[@name='id'][.='+4']",
"//result/doc[3]/str[@name='id'][.='-3']",
"//result/doc[4]/str[@name='id'][.='M1']", "//result/doc[4]/str[@name='id'][.='M1']",
"//result/doc[5]/str[@name='id'][.='M2']" "//result/doc[5]/str[@name='id'][.='M2']"
); );
@ -85,8 +108,8 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"), req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),
"//*[@numFound='5']", "//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='-3']", "//result/doc[1]/str[@name='id'][.='-3']",
"//result/doc[2]/str[@name='id'][.='M1']", "//result/doc[2]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[3]/str[@name='id'][.='M2']", "//result/doc[3]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[4]/str[@name='id'][.='+4']", "//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='+5']" "//result/doc[5]/str[@name='id'][.='+5']"
); );
@ -96,6 +119,26 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
"//*[@numFound='5']", "//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='+5']", "//result/doc[1]/str[@name='id'][.='+5']",
"//result/doc[2]/str[@name='id'][.='+4']", "//result/doc[2]/str[@name='id'][.='+4']",
"//result/doc[3]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[4]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[5]/str[@name='id'][.='-3']"
);
assertQ("Sorting Asc w/secondary on id desc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc, id desc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='-3']",
"//result/doc[2]/str[@name='id'][.='M2']",
"//result/doc[3]/str[@name='id'][.='M1']",
"//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='+5']"
);
assertQ("Sorting Desc w/secondary on id asc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc, id asc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='+5']",
"//result/doc[2]/str[@name='id'][.='+4']",
"//result/doc[3]/str[@name='id'][.='M1']", "//result/doc[3]/str[@name='id'][.='M1']",
"//result/doc[4]/str[@name='id'][.='M2']", "//result/doc[4]/str[@name='id'][.='M2']",
"//result/doc[5]/str[@name='id'][.='-3']" "//result/doc[5]/str[@name='id'][.='-3']"
@ -114,13 +157,32 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
"//result/doc[1]/str[@name='id'][.='-3']", "//result/doc[1]/str[@name='id'][.='-3']",
"//result/doc[2]/str[@name='id'][.='+4']", "//result/doc[2]/str[@name='id'][.='+4']",
"//result/doc[3]/str[@name='id'][.='+5']", "//result/doc[3]/str[@name='id'][.='+5']",
"//result/doc[4]/str[@name='id'][.='M1']", "//result/doc[4]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[5]/str[@name='id'][.='M2']" "//result/doc[5]/str[@name='id'][starts-with(.,'M')]"
); );
// This does not match
assertQ("Sorting Desc: " + t + suffix, assertQ("Sorting Desc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc", "indent", "on"), req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='+5']",
"//result/doc[2]/str[@name='id'][.='+4']",
"//result/doc[3]/str[@name='id'][.='-3']",
"//result/doc[4]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[5]/str[@name='id'][starts-with(.,'M')]"
);
assertQ("Sorting Asc w/secondary on id desc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc, id desc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='-3']",
"//result/doc[2]/str[@name='id'][.='+4']",
"//result/doc[3]/str[@name='id'][.='+5']",
"//result/doc[4]/str[@name='id'][.='M2']",
"//result/doc[5]/str[@name='id'][.='M1']"
);
assertQ("Sorting Desc w/secondary on id asc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc, id asc"),
"//*[@numFound='5']", "//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='+5']", "//result/doc[1]/str[@name='id'][.='+5']",
"//result/doc[2]/str[@name='id'][.='+4']", "//result/doc[2]/str[@name='id'][.='+4']",
@ -134,18 +196,37 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
suffix = "_first"; suffix = "_first";
for (String t : types) { for (String t : types) {
assertQ("Sorting Asc: " + t + suffix, assertQ("Sorting Asc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc", "indent", "on"), req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),
"//*[@numFound='5']", "//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='M1']", "//result/doc[1]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[2]/str[@name='id'][.='M2']", "//result/doc[2]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[3]/str[@name='id'][.='-3']", "//result/doc[3]/str[@name='id'][.='-3']",
"//result/doc[4]/str[@name='id'][.='+4']", "//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='+5']" "//result/doc[5]/str[@name='id'][.='+5']"
); );
// This does not match
assertQ("Sorting Desc: " + t + suffix, assertQ("Sorting Desc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc", "indent", "on"), req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[2]/str[@name='id'][starts-with(.,'M')]",
"//result/doc[3]/str[@name='id'][.='+5']",
"//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='-3']"
);
assertQ("Sorting Asc w/secondary on id desc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc, id desc"),
"//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='M2']",
"//result/doc[2]/str[@name='id'][.='M1']",
"//result/doc[3]/str[@name='id'][.='-3']",
"//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='+5']"
);
assertQ("Sorting Desc w/secondary on id asc: " + t + suffix,
req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc, id asc"),
"//*[@numFound='5']", "//*[@numFound='5']",
"//result/doc[1]/str[@name='id'][.='M1']", "//result/doc[1]/str[@name='id'][.='M1']",
"//result/doc[2]/str[@name='id'][.='M2']", "//result/doc[2]/str[@name='id'][.='M2']",
@ -153,6 +234,7 @@ public class NumericFieldsTest extends SolrTestCaseJ4 {
"//result/doc[4]/str[@name='id'][.='+4']", "//result/doc[4]/str[@name='id'][.='+4']",
"//result/doc[5]/str[@name='id'][.='-3']" "//result/doc[5]/str[@name='id'][.='-3']"
); );
} }
} }
} }