mirror of https://github.com/apache/lucene.git
SOLR-6573: Updated after comments from Hoss, now also supports value parsed from localParam "v=", using rb.getQparser().getLocalParams()
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1633395 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c445d40b80
commit
6d27591ab5
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue