TestFunctionQuery: clear index before each test to avoid cross contamination

This commit is contained in:
Steve Rowe 2017-10-30 11:25:28 -04:00
parent c8d55cc6d4
commit 84fa17d42a
1 changed files with 25 additions and 2 deletions

View File

@ -138,6 +138,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
} }
void doTest(String field) { void doTest(String field) {
clearIndex();
// lrf.args.put("version","2.0"); // lrf.args.put("version","2.0");
int[] vals = { 100,-4,0,10,25,5 }; int[] vals = { 100,-4,0,10,25,5 };
createIndex(field,vals); createIndex(field,vals);
@ -209,6 +211,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testExternalField() throws Exception { public void testExternalField() throws Exception {
clearIndex();
String field = "foo_extf"; String field = "foo_extf";
int[] ids = {100,-4,0,10,25,5,77,23,55,-78,-45,-24,63,78,94,22,34,54321,261,-627}; int[] ids = {100,-4,0,10,25,5,77,23,55,-78,-45,-24,63,78,94,22,34,54321,261,-627};
@ -283,6 +287,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testExternalFileFieldStringKeys() throws Exception { public void testExternalFileFieldStringKeys() throws Exception {
clearIndex();
final String extField = "foo_extfs"; final String extField = "foo_extfs";
final String keyField = "sfile_s"; final String keyField = "sfile_s";
assertU(adoc("id", "991", keyField, "AAA=AAA")); assertU(adoc("id", "991", keyField, "AAA=AAA"));
@ -295,6 +301,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testExternalFileFieldNumericKey() throws Exception { public void testExternalFileFieldNumericKey() throws Exception {
clearIndex();
final String extField = "eff_trie"; final String extField = "eff_trie";
final String keyField = "eff_tint"; final String keyField = "eff_tint";
assertU(adoc("id", "991", keyField, "91")); assertU(adoc("id", "991", keyField, "91"));
@ -512,6 +520,7 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testRetrievePayloads() throws Exception { public void testRetrievePayloads() throws Exception {
clearIndex(); clearIndex();
int numDocs = 100 + random().nextInt(100); int numDocs = 100 + random().nextInt(100);
int numLocations = 1000 + random().nextInt(2000); int numLocations = 1000 + random().nextInt(2000);
for (int docNum = 0 ; docNum < numDocs ; ++docNum) { for (int docNum = 0 ; docNum < numDocs ; ++docNum) {
@ -536,6 +545,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testSortByFunc() throws Exception { public void testSortByFunc() throws Exception {
clearIndex();
assertU(adoc("id", "1", "const_s", "xx", assertU(adoc("id", "1", "const_s", "xx",
"x_i", "100", "1_s", "a", "x_i", "100", "1_s", "a",
"x:x_i", "100", "1-1_s", "a")); "x:x_i", "100", "1-1_s", "a"));
@ -625,7 +636,9 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
} }
@Test @Test
public void testDegreeRads() throws Exception { public void testDegreeRads() throws Exception {
clearIndex();
assertU(adoc("id", "1", "x_td", "0", "y_td", "0")); assertU(adoc("id", "1", "x_td", "0", "y_td", "0"));
assertU(adoc("id", "2", "x_td", "90", "y_td", String.valueOf(Math.PI / 2))); assertU(adoc("id", "2", "x_td", "90", "y_td", String.valueOf(Math.PI / 2)));
assertU(adoc("id", "3", "x_td", "45", "y_td", String.valueOf(Math.PI / 4))); assertU(adoc("id", "3", "x_td", "45", "y_td", String.valueOf(Math.PI / 4)));
@ -643,6 +656,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testStrDistance() throws Exception { public void testStrDistance() throws Exception {
clearIndex();
assertU(adoc("id", "1", "x_s", "foil")); assertU(adoc("id", "1", "x_s", "foil"));
assertU(commit()); assertU(commit());
assertQ(req("fl", "*,score", "q", "{!func}strdist(x_s, 'foit', edit)", "fq", "id:1"), "//float[@name='score']='0.75'"); assertQ(req("fl", "*,score", "q", "{!func}strdist(x_s, 'foit', edit)", "fq", "id:1"), "//float[@name='score']='0.75'");
@ -683,6 +698,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testFuncs() throws Exception { public void testFuncs() throws Exception {
clearIndex();
assertU(adoc("id", "1", "foo_d", "9")); assertU(adoc("id", "1", "foo_d", "9"));
assertU(commit()); assertU(commit());
@ -777,8 +794,10 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
singleTest(fieldAsFunc, "log(\0)", 1,0); singleTest(fieldAsFunc, "log(\0)", 1,0);
} }
@Test @Test
public void testBooleanFunctions() throws Exception { public void testBooleanFunctions() throws Exception {
clearIndex();
assertU(adoc("id", "1", "text", "hello", "foo_s","A", "foo_ti", "0", "foo_tl","0")); assertU(adoc("id", "1", "text", "hello", "foo_s","A", "foo_ti", "0", "foo_tl","0"));
assertU(adoc("id", "2" , "foo_ti","10", "foo_tl","11")); assertU(adoc("id", "2" , "foo_ti","10", "foo_tl","11"));
assertU(commit()); assertU(commit());
@ -844,6 +863,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testPseudoFieldFunctions() throws Exception { public void testPseudoFieldFunctions() throws Exception {
clearIndex();
assertU(adoc("id", "1", "text", "hello", "foo_s","A", "yak_i", "32")); assertU(adoc("id", "1", "text", "hello", "foo_s","A", "yak_i", "32"));
assertU(adoc("id", "2")); assertU(adoc("id", "2"));
assertU(commit()); assertU(commit());
@ -886,6 +907,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
@Test @Test
public void testNumericComparisons() throws Exception { public void testNumericComparisons() throws Exception {
clearIndex();
assertU(adoc("id", "1", "age_i", "35")); assertU(adoc("id", "1", "age_i", "35"));
assertU(adoc("id", "2", "age_i", "25")); assertU(adoc("id", "2", "age_i", "25"));
assertU(commit()); assertU(commit());