SOLR-6318: New terms QParser defaults to comma delimited now

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1616609 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2014-08-07 22:24:40 +00:00
parent 4e3bc61907
commit 4b5f9578e2
3 changed files with 15 additions and 11 deletions

View File

@ -44,8 +44,8 @@ import java.util.regex.Pattern;
* {@link TermQParserPlugin} but multi-valued, and supports a variety of internal algorithms.
* <br>Parameters:
* <br><code>f</code>: The field name (mandatory)
* <br><code>separator</code>: the separator delimiting the values in the query string. By
* default it's a " " which is special in that it splits on any consecutive whitespace.
* <br><code>separator</code>: the separator delimiting the values in the query string, defaulting to a comma.
* If it's a " " then it splits on any consecutive whitespace.
* <br><code>method</code>: Any of termsFilter (default), booleanQuery, automaton, docValuesTermsFilter.
* <p>
* Note that if no values are specified then the query matches no documents.
@ -106,7 +106,7 @@ public class TermsQParserPlugin extends QParserPlugin {
public Query parse() throws SyntaxError {
String fname = localParams.get(QueryParsing.F);
FieldType ft = req.getSchema().getFieldTypeNoEx(fname);
String separator = localParams.get(SEPARATOR, " ");
String separator = localParams.get(SEPARATOR, ",");
String qstr = localParams.get(QueryParsing.V);//never null
Method method = Method.valueOf(localParams.get(METHOD, Method.termsFilter.name()));
//TODO pick the default method based on various heuristics from benchmarks

View File

@ -16,10 +16,6 @@ package org.apache.solr.search;
* limitations under the License.
*/
import java.util.HashSet;
import java.util.Set;
import java.util.Map;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryUtils;
import org.apache.solr.SolrTestCaseJ4;
@ -29,6 +25,10 @@ import org.apache.solr.response.SolrQueryResponse;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
@ -365,6 +365,10 @@ public class QueryEqualityTest extends SolrTestCaseJ4 {
}
}
public void testTerms() throws Exception {
assertQueryEquals("terms", "{!terms f=foo_i}10,20,30,-10,-20,-30", "{!terms f=foo_i}10,20,30,-10,-20,-30");
}
public void testBlockJoin() throws Exception {
assertQueryEquals("parent", "{!parent which=foo_s:parent}dude",
"{!parent which=foo_s:parent}dude");

View File

@ -89,9 +89,9 @@ public class TestQueryTypes extends AbstractSolrTestCase {
);
// terms qparser
//wrap in spaces if space separated
final String separator = f == "v_s" ? "separator='|'" : "";//defaults to space separated
String vMod = separator == "" && random().nextBoolean() ? " " + v + " " : v;
//wrap in spaces sometimes if space separated
final String separator = f == "v_s" ? "" : "separator=' '";//use space separated when field isn't v_s
String vMod = separator != "" && random().nextBoolean() ? " " + v + " " : v;
assertQ(req( "q", "{!terms " + separator + " f=" +f+"}"+vMod)
,"//result[@numFound='1']"
);
@ -108,7 +108,7 @@ public class TestQueryTypes extends AbstractSolrTestCase {
);
String termsMethod = new String[]{"termsFilter", "booleanQuery", "automaton", "docValuesTermsFilter"}[random().nextInt(4)];
assertQ(req( "q", "{!terms f=v_s method=" + termsMethod + " separator=|}other stuff|wow dude")
assertQ(req( "q", "{!terms f=v_s method=" + termsMethod + " }other stuff,wow dude")
,"//result[@numFound='2']"
);