mirror of https://github.com/apache/lucene.git
SOLR-5541: Allow QueryElevationComponent to accept elevateIds and excludeIds as http parameters
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1556903 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a9e4db95ac
commit
23ae54b652
|
@ -139,6 +139,9 @@ New Features
|
|||
|
||||
* SOLR-5536: Add ValueSource collapse criteria to CollapsingQParsingPlugin (Joel Bernstein)
|
||||
|
||||
* SOLR-5541: Allow QueryElevationComponent to accept elevateIds and excludeIds
|
||||
as http parameters (Joel Bernstein)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -339,6 +339,18 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
|
|||
elev.put(obj.analyzed, obj);
|
||||
}
|
||||
|
||||
ElevationObj getElevationObj(String query, String[] ids, String[] ex) throws IOException {
|
||||
if (ids == null) {
|
||||
ids = new String[0];
|
||||
}
|
||||
if (ex == null) {
|
||||
ex = new String[0];
|
||||
}
|
||||
|
||||
ElevationObj obj = new ElevationObj(query, Arrays.asList(ids), Arrays.asList(ex));
|
||||
return obj;
|
||||
}
|
||||
|
||||
String getAnalyzedQuery(String query) throws IOException {
|
||||
if (analyzer == null) {
|
||||
return query;
|
||||
|
@ -373,17 +385,26 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
|
|||
// A runtime parameter can alter the config value for forceElevation
|
||||
boolean force = params.getBool(QueryElevationParams.FORCE_ELEVATION, forceElevation);
|
||||
boolean markExcludes = params.getBool(QueryElevationParams.MARK_EXCLUDES, false);
|
||||
String boostStr = params.get(QueryElevationParams.IDS);
|
||||
String exStr = params.get(QueryElevationParams.EXCLUDE);
|
||||
|
||||
Query query = rb.getQuery();
|
||||
String qstr = rb.getQueryString();
|
||||
if (query == null || qstr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
qstr = getAnalyzedQuery(qstr);
|
||||
IndexReader reader = req.getSearcher().getIndexReader();
|
||||
ElevationObj booster = null;
|
||||
try {
|
||||
booster = getElevationMap(reader, req.getCore()).get(qstr);
|
||||
if(boostStr != null || exStr != null) {
|
||||
String[] boosts = (boostStr != null) ? boostStr.split(",") : new String[0];
|
||||
String[] excludes = (exStr != null) ? exStr.split(",") : new String[0];
|
||||
booster = getElevationObj(qstr, boosts, excludes);
|
||||
} else {
|
||||
IndexReader reader = req.getSearcher().getIndexReader();
|
||||
qstr = getAnalyzedQuery(qstr);
|
||||
booster = getElevationMap(reader, req.getCore()).get(qstr);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||
"Error loading elevation", ex);
|
||||
|
|
|
@ -641,6 +641,32 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
);
|
||||
|
||||
|
||||
// Test setting ids and excludes from http parameters
|
||||
|
||||
booster.elevationCache.clear();
|
||||
args.put(QueryElevationParams.IDS, "x,y,z");
|
||||
args.put(QueryElevationParams.EXCLUDE, "b");
|
||||
|
||||
assertQ("All five should make it", req
|
||||
, "//*[@numFound='5']"
|
||||
, "//result/doc[1]/str[@name='id'][.='x']"
|
||||
, "//result/doc[2]/str[@name='id'][.='y']"
|
||||
, "//result/doc[3]/str[@name='id'][.='z']"
|
||||
, "//result/doc[4]/str[@name='id'][.='a']"
|
||||
, "//result/doc[5]/str[@name='id'][.='c']"
|
||||
);
|
||||
|
||||
args.put(QueryElevationParams.IDS, "x,z,y");
|
||||
args.put(QueryElevationParams.EXCLUDE, "b,c");
|
||||
|
||||
assertQ("All four should make it", req
|
||||
, "//*[@numFound='4']"
|
||||
, "//result/doc[1]/str[@name='id'][.='x']"
|
||||
, "//result/doc[2]/str[@name='id'][.='z']"
|
||||
, "//result/doc[3]/str[@name='id'][.='y']"
|
||||
, "//result/doc[4]/str[@name='id'][.='a']"
|
||||
);
|
||||
|
||||
req.close();
|
||||
} finally {
|
||||
delete();
|
||||
|
|
|
@ -27,6 +27,8 @@ public interface QueryElevationParams {
|
|||
String ENABLE = "enableElevation";
|
||||
String EXCLUSIVE = "exclusive";
|
||||
String FORCE_ELEVATION = "forceElevation";
|
||||
String IDS = "elevateIds";
|
||||
String EXCLUDE = "excludeIds";
|
||||
/**
|
||||
* The name of the field that editorial results will be written out as when using the QueryElevationComponent, which
|
||||
* automatically configures the EditorialMarkerFactory. The default name is "elevated"
|
||||
|
|
Loading…
Reference in New Issue