You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2014/01/09 20:12:55 UTC

svn commit: r1556923 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/handler/component/ solr/core/src/test/org/apache/solr/handler/component/ solr/solrj/ solr/solrj/src/java/org/apache/solr/common/params/

Author: jbernste
Date: Thu Jan  9 19:12:55 2014
New Revision: 1556923

URL: http://svn.apache.org/r1556923
Log:
SOLR-5541: Allow QueryElevationComponent to accept elevateIds and excludeIds as http parameters

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1556923&r1=1556922&r2=1556923&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Thu Jan  9 19:12:55 2014
@@ -100,6 +100,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
 ----------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java?rev=1556923&r1=1556922&r2=1556923&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java Thu Jan  9 19:12:55 2014
@@ -340,6 +340,18 @@ public class QueryElevationComponent ext
     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;
@@ -377,17 +389,26 @@ public class QueryElevationComponent ext
     // 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);

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java?rev=1556923&r1=1556922&r2=1556923&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java Thu Jan  9 19:12:55 2014
@@ -641,6 +641,32 @@ public class QueryElevationComponentTest
       );
 
 
+      // 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();

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java?rev=1556923&r1=1556922&r2=1556923&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/QueryElevationParams.java Thu Jan  9 19:12:55 2014
@@ -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"