SOLR-14139: Support backtick phrase queries in Streaming Expressions

This commit is contained in:
Joel Bernstein 2020-01-31 11:31:38 -05:00
parent 0c1b19a321
commit db78f6cd00
2 changed files with 38 additions and 1 deletions

View File

@ -134,6 +134,17 @@ public class StreamExpressionParser {
}
}
// If contains ` replace with "
// This allows ` to be used as a quote character
if(parameter.contains("`")){
parameter = parameter.replace('`', '"');
if(0 == parameter.length()){
throw new IllegalArgumentException(String.format(Locale.ROOT,"'%s' is not a proper named parameter clause", working));
}
}
namedParameter.setParameter(new StreamExpressionValue(parameter));
}

View File

@ -2625,7 +2625,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
updateRequest.add(id, "hello1", "test_t", "l b c d c");
updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
String expr = "search("+COLLECTIONORALIAS+", q=\"*:*\", fl=\"id,test_t\", sort=\"id desc\")";
String expr = "search("+COLLECTIONORALIAS+", q=\"`c d c`\", fl=\"id,test_t\", sort=\"id desc\")";
//Add a Stream and an Evaluator to the Tuple.
String cat = "tuple(results="+expr+", sum=add(1,1))";
@ -2650,6 +2650,32 @@ public class StreamExpressionTest extends SolrCloudTestCase {
}
@Test
public void testSearchBacktick() throws Exception {
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.add(id, "hello", "test_t", "l b c d c e");
updateRequest.add(id, "hello1", "test_t", "l b c d c");
updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
String expr = "search("+COLLECTIONORALIAS+", q=\"`c d c e`\", fl=\"id,test_t\", sort=\"id desc\")";
ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
paramsLoc.set("expr", expr);
paramsLoc.set("qt", "/stream");
String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
TupleStream solrStream = new SolrStream(url, paramsLoc);
StreamContext context = new StreamContext();
solrStream.setStreamContext(context);
List<Tuple> tuples = getTuples(solrStream);
assertTrue(tuples.size() == 1);
Tuple tuple = tuples.get(0);
assertTrue(tuple.get("id").equals("hello"));
assertTrue(tuple.get("test_t").equals("l b c d c e"));
}
private Map<String,Double> getIdToLabel(TupleStream stream, String outField) throws IOException {
Map<String, Double> idToLabel = new HashMap<>();