SOLR-13080: TermsQParserPlugin automaton method should (must?) sort input

This commit is contained in:
David Smiley 2018-12-21 13:26:03 -05:00
parent 207b3f4453
commit 1d0a086217
3 changed files with 7 additions and 2 deletions

View File

@ -182,6 +182,9 @@ Bug Fixes
* SOLR-13072: Management of markers for nodeLost / nodeAdded events is broken. This bug could have caused
some events to be lost if they coincided with an Overseer leader crash. (ab)
* SOLR-13080: The "terms" QParser's "automaton" method semi-required that the input terms/IDs be sorted. This
query parser now does this. Unclear if this is a perf issue or actual bug. (Daniel Lowe, David Smiley)
Improvements
----------------------

View File

@ -30,6 +30,7 @@ import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.automaton.Automata;
@ -79,7 +80,8 @@ public class TermsQParserPlugin extends QParserPlugin {
automaton {
@Override
Query makeFilter(String fname, BytesRef[] byteRefs) {
Automaton union = Automata.makeStringUnion(Arrays.asList(byteRefs));
ArrayUtil.timSort(byteRefs); // same sort algo as TermInSetQuery's choice
Automaton union = Automata.makeStringUnion(Arrays.asList(byteRefs)); // input must be sorted
return new AutomatonQuery(new Term(fname), union);//constant scores
}
},

View File

@ -109,7 +109,7 @@ public class TestQueryTypes extends SolrTestCaseJ4 {
);
String termsMethod = new String[]{"termsFilter", "booleanQuery", "automaton", "docValuesTermsFilter"}[random().nextInt(4)];
assertQ(req( "q", "{!terms f=v_s method=" + termsMethod + " }other stuff,wow dude")
assertQ(req( "q", "{!terms f=v_s method=" + termsMethod + " }wow dude,other stuff")//terms reverse sorted to show this works
,"//result[@numFound='2']"
);