SOLR-13403: test terms component with point fields on empty index

This commit is contained in:
Munendra S N 2019-10-24 10:06:16 +05:30
parent 9a108996bb
commit 255bdaebbc
4 changed files with 64 additions and 47 deletions

View File

@ -207,9 +207,9 @@ public class TermsComponent extends SearchComponent {
String.format(Locale.ROOT, "The terms component does not support Points-based fields with sorting or with parameters %s,%s,%s,%s ", TermsParams.TERMS_LOWER, TermsParams.TERMS_UPPER, TermsParams.TERMS_PREFIX_STR, TermsParams.TERMS_REGEXP_STR));
}
PointMerger.ValueIterator valueIterator = new PointMerger.ValueIterator(sf, rb.req.getSearcher().getRawReader().leaves());
MutableValue mv = valueIterator.getMutableValue();
if (sort) {
PointMerger.ValueIterator valueIterator = new PointMerger.ValueIterator(sf, rb.req.getSearcher().getRawReader().leaves());
MutableValue mv = valueIterator.getMutableValue();
BoundedTreeSet<CountPair<MutableValue, Integer>> queue = new BoundedTreeSet<>(limit);
for (; ; ) {
@ -230,8 +230,6 @@ public class TermsComponent extends SearchComponent {
// streaming solution that is deferred until writing the response
// TODO: we can't use the streaming solution until XML writer supports PushWriter!
termsResult.add(field, (MapWriter) ew -> {
PointMerger.ValueIterator valueIterator = new PointMerger.ValueIterator(sf, rb.req.getSearcher().getRawReader().leaves());
MutableValue mv = valueIterator.getMutableValue();
int num = 0;
for(;;) {
long count = valueIterator.getNextCount();
@ -243,8 +241,6 @@ public class TermsComponent extends SearchComponent {
});
***/
PointMerger.ValueIterator valueIterator = new PointMerger.ValueIterator(sf, rb.req.getSearcher().getRawReader().leaves());
MutableValue mv = valueIterator.getMutableValue();
int num = 0;
for(;;) {
long count = valueIterator.getNextCount();

View File

@ -57,6 +57,9 @@ public class PointMerger {
public ValueIterator(SchemaField field, List<LeafReaderContext> readers, int totalBufferSize, int minSegBufferSize) throws IOException {
assert field.getType().isPointField();
queue = new PQueue(readers.size());
if (readers.isEmpty()) {
return;
}
long ndocs = readers.get(readers.size()-1).docBase + readers.get(readers.size()-1).reader().maxDoc();
for (LeafReaderContext ctx : readers) {
PointValues pv = ctx.reader().getPointValues(field.getName());

View File

@ -36,9 +36,16 @@ public class DistributedTermsComponentTest extends BaseDistributedSearchTestCase
@Test
public void test() throws Exception {
Random random = random();
del("*:*");
index(id, random.nextInt(), "b_t", "snake a,b spider shark snail slug seal", "foo_i_p", "1");
query("qt", "/terms", "shards.qt", "/terms", "terms", "true", "terms.fl", "foo_i_p");
del("*:*");
// verify point field on empty index
query("qt", "/terms", "shards.qt", "/terms", "terms", "true", "terms.fl", "foo_i_p");
index(id, random.nextInt(), "b_t", "snake a,b spider shark snail slug seal", "foo_i", "1");
index(id, random.nextInt(), "b_t", "snake spider shark snail slug", "foo_i", "2", "foo_date_p", "2015-01-03T14:30:00Z");
index(id, random.nextInt(), "b_t", "snake spider shark snail", "foo_i", "3");
@ -67,9 +74,8 @@ public class DistributedTermsComponentTest extends BaseDistributedSearchTestCase
query("qt", "/terms", "shards.qt", "/terms", "terms", "true", "terms.fl", "b_t", "terms.list", "snake,zebra", "terms.ttf", "true");
query("qt", "/terms", "shards.qt", "/terms", "terms", "true", "terms.fl", "b_t", "terms.fl", "c_t", "terms.list", "snake,ant,zebra", "terms.ttf", "true");
// TODO: SOLR-13403 fix distributed failure case
// for date point field
//query("qt", "/terms", "shards.qt", "/terms", "terms", "true", "terms.fl", "foo_date_p");
query("qt", "/terms", "shards.qt", "/terms", "terms", "true", "terms.fl", "foo_date_p");
// terms.ttf=true doesn't work for point fields
//query("qt", "/terms", "shards.qt", "/terms", "terms", "true", "terms.fl", "foo_date_p", "terms.ttf", "true");
}

View File

@ -29,6 +29,7 @@ import org.apache.solr.common.params.TermsParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.PointMerger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -39,40 +40,47 @@ public class TermsComponentTest extends SolrTestCaseJ4 {
public static void beforeTest() throws Exception {
System.setProperty("enable.update.log", "false"); // schema12 doesn't support _version_
initCore("solrconfig.xml", "schema12.xml");
}
assertNull(h.validateUpdate(adoc("id", "0", "lowerfilt", "a", "standardfilt", "a", "foo_i", "1")));
assertNull(h.validateUpdate(adoc("id", "1", "lowerfilt", "a", "standardfilt", "aa", "foo_i","1")));
assertNull(h.validateUpdate(adoc("id", "2", "lowerfilt", "aa", "standardfilt", "aaa", "foo_i","2")));
assertNull(h.validateUpdate(adoc("id", "3", "lowerfilt", "aaa", "standardfilt", "abbb")));
assertNull(h.validateUpdate(adoc("id", "4", "lowerfilt", "ab", "standardfilt", "b")));
assertNull(h.validateUpdate(adoc("id", "5", "lowerfilt", "abb", "standardfilt", "bb")));
assertNull(h.validateUpdate(adoc("id", "6", "lowerfilt", "abc", "standardfilt", "bbbb")));
assertNull(h.validateUpdate(adoc("id", "7", "lowerfilt", "b", "standardfilt", "c")));
assertNull(h.validateUpdate(adoc("id", "8", "lowerfilt", "baa", "standardfilt", "cccc")));
assertNull(h.validateUpdate(adoc("id", "9", "lowerfilt", "bbb", "standardfilt", "ccccc")));
@Before
public void createIndex() {
// cleanup first
assertU(delQ("*:*"));
assertU(commit());
assertU(adoc("id", "0", "lowerfilt", "a", "standardfilt", "a", "foo_i", "1"));
assertU(adoc("id", "1", "lowerfilt", "a", "standardfilt", "aa", "foo_i","1"));
assertU(adoc("id", "2", "lowerfilt", "aa", "standardfilt", "aaa", "foo_i","2"));
assertU(adoc("id", "3", "lowerfilt", "aaa", "standardfilt", "abbb"));
assertU(adoc("id", "4", "lowerfilt", "ab", "standardfilt", "b"));
assertU(adoc("id", "5", "lowerfilt", "abb", "standardfilt", "bb"));
assertU(adoc("id", "6", "lowerfilt", "abc", "standardfilt", "bbbb"));
assertU(adoc("id", "7", "lowerfilt", "b", "standardfilt", "c"));
assertU(adoc("id", "8", "lowerfilt", "baa", "standardfilt", "cccc"));
assertU(adoc("id", "9", "lowerfilt", "bbb", "standardfilt", "ccccc"));
assertNull(h.validateUpdate(adoc("id", "10", "standardfilt", "ddddd")));
assertU(adoc("id", "10", "standardfilt", "ddddd"));
assertU(commit());
assertNull(h.validateUpdate(commit()));
assertNull(h.validateUpdate(adoc("id", "11", "standardfilt", "ddddd")));
assertNull(h.validateUpdate(adoc("id", "12", "standardfilt", "ddddd")));
assertNull(h.validateUpdate(adoc("id", "13", "standardfilt", "ddddd")));
assertNull(h.validateUpdate(adoc("id", "14", "standardfilt", "d")));
assertNull(h.validateUpdate(adoc("id", "15", "standardfilt", "d")));
assertNull(h.validateUpdate(adoc("id", "16", "standardfilt", "d")));
assertU(adoc("id", "11", "standardfilt", "ddddd"));
assertU(adoc("id", "12", "standardfilt", "ddddd"));
assertU(adoc("id", "13", "standardfilt", "ddddd"));
assertU(adoc("id", "14", "standardfilt", "d"));
assertU(adoc("id", "15", "standardfilt", "d"));
assertU(adoc("id", "16", "standardfilt", "d"));
assertNull(h.validateUpdate(commit()));
assertU(commit());
assertNull(h.validateUpdate(adoc("id", "17", "standardfilt", "snake")));
assertNull(h.validateUpdate(adoc("id", "18", "standardfilt", "spider")));
assertNull(h.validateUpdate(adoc("id", "19", "standardfilt", "shark")));
assertNull(h.validateUpdate(adoc("id", "20", "standardfilt", "snake")));
assertNull(h.validateUpdate(adoc("id", "21", "standardfilt", "snake")));
assertNull(h.validateUpdate(adoc("id", "22", "standardfilt", "shark")));
assertNull(h.validateUpdate(adoc("id", "23", "standardfilt", "a,b")));
assertU(adoc("id", "17", "standardfilt", "snake"));
assertU(adoc("id", "18", "standardfilt", "spider"));
assertU(adoc("id", "19", "standardfilt", "shark"));
assertU(adoc("id", "20", "standardfilt", "snake"));
assertU(adoc("id", "21", "standardfilt", "snake"));
assertU(adoc("id", "22", "standardfilt", "shark"));
assertU(adoc("id", "23", "standardfilt", "a,b"));
assertNull(h.validateUpdate(commit()));
assertU(commit());
}
@Test
@ -594,16 +602,20 @@ public class TermsComponentTest extends SolrTestCaseJ4 {
assertU(adoc("id", Integer.toString(100102), "foo_pdt", dates[1]));
assertU(commit());
try {
assertQ(req("indent","true", "qt","/terms", "terms","true",
"terms.fl","foo_pdt", "terms.sort","count"),
"count(//lst[@name='foo_pdt']/*)=2",
"//lst[@name='foo_pdt']/int[1][@name='" + dates[1] + "'][.='51']",
"//lst[@name='foo_pdt']/int[2][@name='" + dates[0] + "'][.='50']"
);
} finally {
assertU(delQ("foo_pdt:[* TO *]"));
assertU(commit());
}
assertQ(req("indent","true", "qt","/terms", "terms","true",
"terms.fl","foo_pdt", "terms.sort","count"),
"count(//lst[@name='foo_pdt']/*)=2",
"//lst[@name='foo_pdt']/int[1][@name='" + dates[1] + "'][.='51']",
"//lst[@name='foo_pdt']/int[2][@name='" + dates[0] + "'][.='50']"
);
// test on empty index
assertU(delQ("*:*"));
assertU(commit());
assertQ(req("indent","true", "qt","/terms", "terms","true",
"terms.fl","foo_pdt", "terms.sort","count"),
"count(//lst[@name='foo_pdt']/*)=0"
);
}
}