lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jan...@apache.org
Subject svn commit: r1633395 - in /lucene/dev/trunk/solr/core/src: java/org/apache/solr/handler/component/QueryElevationComponent.java test/org/apache/solr/handler/component/QueryElevationComponentTest.java
Date Tue, 21 Oct 2014 15:13:08 GMT
Author: janhoy
Date: Tue Oct 21 15:13:07 2014
New Revision: 1633395

URL: http://svn.apache.org/r1633395
Log:
SOLR-6573: Updated after comments from Hoss, now also supports value parsed from localParam
"v=", using rb.getQparser().getLocalParams()

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java?rev=1633395&r1=1633394&r2=1633395&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
Tue Oct 21 15:13:07 2014
@@ -49,6 +49,7 @@ import org.apache.solr.common.params.Que
 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 ext
     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 ext
     }
   }
 
-  /**
-   * 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);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java?rev=1633395&r1=1633394&r2=1633395&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
Tue Oct 21 15:13:07 2014
@@ -728,13 +728,6 @@ public class QueryElevationComponentTest
 
   @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
       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();
     }



Mime
View raw message