You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2014/10/20 22:47:50 UTC

svn commit: r1633223 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java

Author: janhoy
Date: Mon Oct 20 20:47:50 2014
New Revision: 1633223

URL: http://svn.apache.org/r1633223
Log:
SOLR-6573: QueryElevationComponent now works with localParams in the query

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    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/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1633223&r1=1633222&r2=1633223&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Oct 20 20:47:50 2014
@@ -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
 ----------------------
 

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=1633223&r1=1633222&r2=1633223&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 Mon Oct 20 20:47:50 2014
@@ -388,7 +388,7 @@ public class QueryElevationComponent ext
     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 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=1633223&r1=1633222&r2=1633223&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 Mon Oct 20 20:47:50 2014
@@ -725,4 +725,31 @@ public class QueryElevationComponentTest
       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();
+    }
+  }
 }



Re: svn commit: r1633223 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java core/src/test/org/apache/solr/handler/component/QueryElevationComponentTes t.java

Posted by Chris Hostetter <ho...@fucit.org>.
Hey Jan,

if the goal here is to get the un-parsed query string, independent of any 
possible localparams, then the "best" way to do that is to use the 
QParser.getParser statc method to parse things, and then pull the "v" 
param (QueryParsing.V) out of the Local Params that you get.

Even that much may not be neccessary if QueryComponent.prepare() has 
already been run -- then you already know *exactly* what QParser was used 
(no need to parse again) and you can get it from the ResponseBuilder & ask 
it for it's local params...

String s = rb.getQparser().getLocalParams().get(QueryParsing.V)


this logic you added here...

: +    if (queryString == null || !queryString.startsWith("{!") || queryString.indexOf("}") == -1) {
: +      return queryString;
: +    }
: +
: +    return queryString.substring(queryString.indexOf("}")+1);

...probably isn't going to do what folks expect in a situation like 
this...

	q={!lucene q.op=AND v=$qq}&qq=foo



-Hoss
http://www.lucidworks.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org