Apache Solr open-source search software
SOLR-13080: TermsQParserPlugin automaton method should (must?) sort input
David Smiley1d0a08621708
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex e77b5641205..cad1a69a87e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -182,6 +182,9 @@ Bug Fixes* SOLR-13072: Management of markers for nodeLost / nodeAdded events is broken. This bug could have causedsome 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----------------------diff --git a/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.javaindex 45bb13fc310..805cca33b06 100644--- a/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java@@ -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 {@OverrideQuery 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 sortedreturn new AutomatonQuery(new Term(fname), union);//constant scores}},diff --git a/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java b/solr/core/src/test/org/apache/solr/search/TestQueryTypes.javaindex 29c9a37a992..ff05e1a22f8 100644--- a/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java+++ b/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java@@ -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']");