mirror of https://github.com/apache/lucene.git
SOLR-6573: QueryElevationComponent now works with localParams in the query
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1633223 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c1556a6136
commit
c1bdf27d97
|
@ -248,6 +248,8 @@ Bug Fixes
|
|||
* SOLR-6307: Atomic update remove does not work for int array or date array
|
||||
(Anurag Sharma , noble)
|
||||
|
||||
* SOLR-6573: QueryElevationComponent now works with localParams in the query (janhoy)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -388,7 +388,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
|
|||
String exStr = params.get(QueryElevationParams.EXCLUDE);
|
||||
|
||||
Query query = rb.getQuery();
|
||||
String qstr = rb.getQueryString();
|
||||
String qstr = QueryElevationComponent.stripLocalParams(rb.getQueryString());
|
||||
if (query == null || qstr == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -490,6 +490,19 @@ 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);
|
||||
|
|
|
@ -725,4 +725,31 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
delete();
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
assertU(commit());
|
||||
assertU(adoc("id", "7", "text", "AAAA", "str_s", "a"));
|
||||
assertU(commit());
|
||||
|
||||
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']"
|
||||
);
|
||||
} finally {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue