Apache Lucene open-source search software
SOLR-5541: Allow QueryElevationComponent to accept elevateIds and excludeIds as http parameters
Joel Bernstein23ae54b652c7
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 573ed3f8f2d..6b30f95f00a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -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----------------------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.javaindex 15ca4e695fa..234a82609ca 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@@ -339,6 +339,18 @@ public class QueryElevationComponent extends SearchComponent implements SolrCoreelev.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 forceElevationboolean 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);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.javaindex 576b8f78207..4b19022c462 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@@ -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();diff --git a/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java b/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.javaindex 0183501e664..7519339ce65 100644--- a/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java+++ b/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java@@ -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"