You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jd...@apache.org on 2012/06/11 19:29:17 UTC

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

Author: jdyer
Date: Mon Jun 11 17:29:17 2012
New Revision: 1348937

URL: http://svn.apache.org/viewvc?rev=1348937&view=rev
Log:
SOLR-3211:  Allow parameter overrides when testing spellcheck collations

Modified:
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.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=1348937&r1=1348936&r2=1348937&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Mon Jun 11 17:29:17 2012
@@ -347,6 +347,11 @@ New Features
     {"delete":{"id":"myid", "_version_":123456789}}
   (yonik)
 
+* SOLR-3211:  Allow parameter overrides in conjunction with "spellcheck.maxCollationTries".
+  To do so, use parameters starting with "spellcheck.collateParam."  For instance, to
+  override the "mm" parameter, specify "spellcheck.collateParam.mm".  This is helpful
+  in cases where testing spellcheck collations for result counts should use different
+  parameters from the main query (James Dyer)
 
 Optimizations
 ----------------------

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java?rev=1348937&r1=1348936&r2=1348937&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java Mon Jun 11 17:29:17 2012
@@ -18,12 +18,15 @@ package org.apache.solr.spelling;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.lucene.analysis.Token;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.GroupParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.params.SpellingParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.handler.component.QueryComponent;
 import org.apache.solr.handler.component.ResponseBuilder;
@@ -74,8 +77,23 @@ public class SpellCheckCollator {
 
       if (verifyCandidateWithQuery) {
         tryNo++;
-
-        ModifiableSolrParams params = new ModifiableSolrParams(ultimateResponse.req.getParams());
+        SolrParams origParams = ultimateResponse.req.getParams();
+        ModifiableSolrParams params = new ModifiableSolrParams(origParams);  
+        Iterator<String> origParamIterator = origParams.getParameterNamesIterator();
+        int pl = SpellingParams.SPELLCHECK_COLLATE_PARAM_OVERRIDE.length();
+        while (origParamIterator.hasNext()) {
+          String origParamName = origParamIterator.next();
+          if (origParamName
+              .startsWith(SpellingParams.SPELLCHECK_COLLATE_PARAM_OVERRIDE)
+              && origParamName.length() > pl) {
+            String[] val = origParams.getParams(origParamName);
+            if (val.length == 1 && val[0].length() == 0) {
+              params.set(origParamName.substring(pl), (String[]) null);
+            } else {
+              params.set(origParamName.substring(pl), val);
+            }
+          }
+        }
         params.set(CommonParams.Q, collationQueryStr);
         params.remove(CommonParams.START);
         params.set(CommonParams.FL, "id");

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java?rev=1348937&r1=1348936&r2=1348937&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java Mon Jun 11 17:29:17 2012
@@ -54,6 +54,7 @@ public class SpellCheckCollatorTest exte
  		assertNull(h.validateUpdate(adoc("id", "10", "teststop", "Once in Paris Dick built a fire on the hearth")));
  		assertNull(h.validateUpdate(adoc("id", "11", "teststop", "Dick waited for Jane as he watched the sparks flow upward")));
  		assertNull(h.validateUpdate(adoc("id", "12", "teststop", "This June parisian rendez-vous is ruined because of a customs snafu")));
+ 		assertNull(h.validateUpdate(adoc("id", "13", "teststop", "partisan political machine")));
 		assertNull(h.validateUpdate(commit()));
 	}
 
@@ -108,6 +109,44 @@ public class SpellCheckCollatorTest exte
     }
 
   }
+	
+	public void testCollateWithOverride() throws Exception
+	{
+	  assertQ(
+      req(
+    	  SpellCheckComponent.COMPONENT_NAME, "true",
+        SpellCheckComponent.SPELLCHECK_DICT, "direct",
+        SpellingParams.SPELLCHECK_COUNT, "10",   
+        SpellingParams.SPELLCHECK_COLLATE, "true",
+        SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10",
+        SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10",
+        "qt", "spellCheckCompRH",
+        "defType", "edismax",
+        "qf", "teststop",
+        "mm", "1",
+        CommonParams.Q, "partisian politcal mashine"
+      ),
+      "//lst[@name='spellcheck']/lst[@name='suggestions']/str[@name='collation']='parisian political machine'"
+    );
+	  assertQ(
+	      req(
+	        SpellCheckComponent.COMPONENT_NAME, "true",
+	        SpellCheckComponent.SPELLCHECK_DICT, "direct",
+	        SpellingParams.SPELLCHECK_COUNT, "10",   
+	        SpellingParams.SPELLCHECK_COLLATE, "true",
+	        SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10",
+	        SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10",
+	        "qt", "spellCheckCompRH",
+	        "defType", "edismax",
+	        "qf", "teststop",
+	        "mm", "1",
+	        SpellingParams.SPELLCHECK_COLLATE_PARAM_OVERRIDE + "mm", "100%",
+	        CommonParams.Q, "partisian politcal mashine"
+	      ),
+	     "//lst[@name='spellcheck']/lst[@name='suggestions']/str[@name='collation']='partisan political machine'"
+	   );
+    
+	}
 
 	@Test
 	public void testCollateWithFilter() throws Exception

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.java?rev=1348937&r1=1348936&r2=1348937&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/params/SpellingParams.java Mon Jun 11 17:29:17 2012
@@ -138,7 +138,15 @@ public interface SpellingParams {
    * </p>
    */
   public static final String SPELLCHECK_COLLATE_EXTENDED_RESULTS = SPELLCHECK_PREFIX + "collateExtendedResults";
-    
+  
+  /**
+   * <p>
+   * For use with {@link SpellingParams#SPELLCHECK_MAX_COLLATION_TRIES}, use this to override any original query parameters
+   * when issuing test queries.  For instance, if the original query has "mm=1" but it is preferred to test collations
+   * with "mm=100%", then use "spellcheck.collateParam.mm=100%".
+   * </p>
+   */
+  public static final String SPELLCHECK_COLLATE_PARAM_OVERRIDE = SPELLCHECK_PREFIX + "collateParam.";
   /**
    * Certain spelling implementations may allow for an accuracy setting.
    */