diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java index ee4736ef276..235c3e08333 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java @@ -49,6 +49,7 @@ import org.apache.solr.common.params.QueryElevationParams; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.StrUtils; import org.apache.solr.schema.IndexSchema; +import org.apache.solr.search.QueryParsing; import org.apache.solr.search.grouping.GroupingSpecification; import org.apache.solr.util.DOMUtil; import org.apache.solr.common.util.NamedList; @@ -388,7 +389,8 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore String exStr = params.get(QueryElevationParams.EXCLUDE); Query query = rb.getQuery(); - String qstr = QueryElevationComponent.stripLocalParams(rb.getQueryString()); + SolrParams localParams = rb.getQparser().getLocalParams(); + String qstr = localParams == null ? rb.getQueryString() : localParams.get(QueryParsing.V); if (query == null || qstr == null) { return; } @@ -490,19 +492,6 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore } } - /** - * Simple stripping of localParam at start of query - * @param queryString the raw query string - * @return the query string without localParams, or the original queryString if no valid localParam found at beginning of string - */ - protected static String stripLocalParams(String queryString) { - if (queryString == null || !queryString.startsWith("{!") || queryString.indexOf("}") == -1) { - return queryString; - } - - return queryString.substring(queryString.indexOf("}")+1); - } - private Sort modifySort(SortField[] current, boolean force, ElevationComparatorSource comparator) { SortSpec tmp = new SortSpec(new Sort(current), Arrays.asList(new SchemaField[current.length])); tmp = modifySortSpec(tmp, force, comparator); diff --git a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java index 0f4905ad923..27bdd665f27 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java @@ -728,13 +728,6 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 { @Test public void testWithLocalParam() throws Exception { - assertEquals("foo", QueryElevationComponent.stripLocalParams("foo")); - assertEquals("foo", QueryElevationComponent.stripLocalParams("{!param=value}foo")); - assertEquals("", QueryElevationComponent.stripLocalParams("{!param=value}")); - assertEquals("{!notTerminated", QueryElevationComponent.stripLocalParams("{!notTerminated")); - assertEquals("{notLocalParam}foo", QueryElevationComponent.stripLocalParams("{notLocalParam}foo")); - assertEquals(null, QueryElevationComponent.stripLocalParams(null)); - try { init("schema11.xml"); clearIndex(); @@ -742,12 +735,24 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 { assertU(adoc("id", "7", "text", "AAAA", "str_s", "a")); assertU(commit()); + assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate", + CommonParams.FL, "id, score, [elevated]") + , "//*[@numFound='1']" + , "//result/doc[1]/float[@name='id'][.='7.0']" + , "//result/doc[1]/bool[@name='[elevated]'][.='true']" + ); assertQ("", req(CommonParams.Q, "{!q.op=AND}AAAA", CommonParams.QT, "/elevate", CommonParams.FL, "id, score, [elevated]") , "//*[@numFound='1']" , "//result/doc[1]/float[@name='id'][.='7.0']" , "//result/doc[1]/bool[@name='[elevated]'][.='true']" ); + assertQ("", req(CommonParams.Q, "{!q.op=AND v='AAAA'}", CommonParams.QT, "/elevate", + CommonParams.FL, "id, score, [elevated]") + , "//*[@numFound='1']" + , "//result/doc[1]/float[@name='id'][.='7.0']" + , "//result/doc[1]/bool[@name='[elevated]'][.='true']" + ); } finally { delete(); }