You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/06/08 00:48:42 UTC

svn commit: r1133187 - in /lucene/dev/trunk/solr: ./ src/java/org/apache/solr/handler/component/ src/java/org/apache/solr/spelling/ src/test-files/solr/conf/ src/test/org/apache/solr/handler/component/ src/test/org/apache/solr/spelling/

Author: rmuir
Date: Tue Jun  7 22:48:41 2011
New Revision: 1133187

URL: http://svn.apache.org/viewvc?rev=1133187&view=rev
Log:
SOLR-2576: DirectSolrSpellChecker was not returning freq info for the original token

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellingResult.java
    lucene/dev/trunk/solr/src/test-files/solr/conf/solrconfig-spellcheckcomponent.xml
    lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Jun  7 22:48:41 2011
@@ -94,8 +94,8 @@ New Features
 * SOLR-792: Adding PivotFacetComponent for Hierarchical faceting
   (erik, Jeremy Hinegardner, Thibaut Lassalle, ryan)
 
-* LUCENE-2507, SOLR-2571: Added DirectSolrSpellChecker, which uses Lucene's DirectSpellChecker
-  to retrieve correction candidates directly from the term dictionary using
+* LUCENE-2507, SOLR-2571, SOLR-2576: Added DirectSolrSpellChecker, which uses Lucene's
+  DirectSpellChecker to retrieve correction candidates directly from the term dictionary using
   levenshtein automata.  (James Dyer, rmuir)
    
 * SOLR-1873: SolrCloud - added shared/central config and core/shard managment via zookeeper,
@@ -256,6 +256,9 @@ Other Changes
   HighFrequencyDictionary, SortedIterator, TermFreqIterator, and the
   suggester APIs and implementations. (rmuir)
 
+* SOLR-2576: Remove deprecated SpellingResult.add(Token, int).
+  (James Dyer via rmuir)
+
 Documentation
 ----------------------
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/SpellCheckComponent.java?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/SpellCheckComponent.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/SpellCheckComponent.java Tue Jun  7 22:48:41 2011
@@ -435,7 +435,7 @@ public class SpellCheckComponent extends
 
       if (extendedResults) {
         Integer o = origVsFreq.get(original);
-        if (o != null) result.add(token, o);
+        if (o != null) result.addFrequency(token, o);
         for (SuggestWord word : suggestions)
           result.add(token, word.string, word.freq);
       } else {

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java Tue Jun  7 22:48:41 2011
@@ -182,7 +182,7 @@ public abstract class AbstractLuceneSpel
 
       if (options.extendedResults == true && reader != null && field != null) {
         term = term.createTerm(tokenText);
-        result.add(token, reader.docFreq(term));
+        result.addFrequency(token, reader.docFreq(term));
         int countLimit = Math.min(options.count, suggestions.length);
         if(countLimit>0)
         {

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java Tue Jun  7 22:48:41 2011
@@ -27,6 +27,7 @@ import org.apache.lucene.search.spell.St
 import org.apache.lucene.search.spell.SuggestWord;
 import org.apache.lucene.search.spell.SuggestWordFrequencyComparator;
 import org.apache.lucene.search.spell.SuggestWordQueue;
+import org.apache.solr.common.params.SpellingParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.search.SolrIndexSearcher;
@@ -179,10 +180,13 @@ public class DirectSolrSpellChecker exte
     float accuracy = (options.accuracy == Float.MIN_VALUE) ? checker.getAccuracy() : options.accuracy;
     
     for (Token token : options.tokens) {
-      SuggestWord[] suggestions = checker.suggestSimilar(new Term(field, token.toString()), 
+    	Term term = new Term(field, token.toString());
+      SuggestWord[] suggestions = checker.suggestSimilar(term, 
           options.count, options.reader, options.onlyMorePopular, accuracy);
-      for (SuggestWord suggestion : suggestions)
-        result.add(token, suggestion.string, suggestion.freq);
+      result.addFrequency(token, options.reader.docFreq(term));
+      for (SuggestWord suggestion : suggestions) {
+        result.add(token, suggestion.string, suggestion.freq);      	
+      }
     }
     return result;
   }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellingResult.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellingResult.java?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellingResult.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellingResult.java Tue Jun  7 22:48:41 2011
@@ -66,7 +66,13 @@ public class SpellingResult {
     }
   }
 
-  public void add(Token token, int docFreq) {
+  /**
+   * Adds an original token with its document frequency
+   * 
+   * @param token original token
+   * @param docFreq original token's document frequency
+   */
+  public void addFrequency(Token token, int docFreq) {
     if (tokenFrequency == null) {
       tokenFrequency = new LinkedHashMap<Token, Integer>();
     }

Modified: lucene/dev/trunk/solr/src/test-files/solr/conf/solrconfig-spellcheckcomponent.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test-files/solr/conf/solrconfig-spellcheckcomponent.xml?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test-files/solr/conf/solrconfig-spellcheckcomponent.xml (original)
+++ lucene/dev/trunk/solr/src/test-files/solr/conf/solrconfig-spellcheckcomponent.xml Tue Jun  7 22:48:41 2011
@@ -50,6 +50,12 @@ Config for testing spellcheck component
       <str name="buildOnCommit">true</str>
     </lst>
     <lst name="spellchecker">
+      <str name="name">direct</str>
+      <str name="classname">solr.DirectSolrSpellChecker</str>
+      <int name="minQueryLength">3</int>
+      <str name="field">teststop</str>
+    </lst>
+    <lst name="spellchecker">
       <str name="name">threshold</str>
       <str name="field">lowerfilt</str>
       <str name="spellcheckIndexDir">spellcheckerThreshold</str>

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java Tue Jun  7 22:48:41 2011
@@ -198,16 +198,15 @@ public class SpellCheckComponentTest ext
     public void testThresholdTokenFrequency() throws Exception {
     	
   	  	//"document" is in 2 documents but "another" is only in 1.  
-  	  	//So with a threshold of 15%, "another" is absent from the dictionary 
+  	  	//So with a threshold of 29%, "another" is absent from the dictionary 
   	  	//while "document" is present.
     	
   	  	assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","documenq", SpellCheckComponent.SPELLCHECK_DICT, "threshold", SpellCheckComponent.SPELLCHECK_COUNT,"5", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS,"true")
   	        ,"/spellcheck/suggestions/[1]/suggestion==[{'word':'document','freq':2}]"
   	    );
   	  	
-  	  	//TODO:  DirectSolrSpellChecker returns a different format.  Is this OK?  Does SOLRJ need tweaking to handle this???
   	  	assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","documenq", SpellCheckComponent.SPELLCHECK_DICT, "threshold_direct", SpellCheckComponent.SPELLCHECK_COUNT,"5", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS,"true")
-  	        ,"/spellcheck/suggestions/[1]/suggestion==['document']]"
+  	        ,"/spellcheck/suggestions/[1]/suggestion==[{'word':'document','freq':2}]"
   	    );
   	  	
   	  	//TODO:  how do we make this into a 1-liner using "assertQ()" ???
@@ -246,7 +245,6 @@ public class SpellCheckComponentTest ext
   			suggestions = (NamedList) spellCheck.get("suggestions");
   			assertTrue(suggestions.get("suggestion")==null);
   			
-  			//TODO: Why is DirectSolrSpellChecker returning "true" here?  Is that OK?
-  			//assertTrue((Boolean) suggestions.get("correctlySpelled")==false);
+  			assertTrue((Boolean) suggestions.get("correctlySpelled")==false);
     }
 }

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java?rev=1133187&r1=1133186&r2=1133187&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java Tue Jun  7 22:48:41 2011
@@ -22,10 +22,14 @@ import java.util.Map;
 
 import org.apache.lucene.analysis.Token;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.SolrCore;
+import org.apache.solr.handler.component.SpellCheckComponent;
+import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.util.RefCounted;
+import org.apache.solr.util.TestHarness;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -38,12 +42,13 @@ public class DirectSolrSpellCheckerTest 
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    initCore("solrconfig.xml","schema.xml");
+    initCore("solrconfig-spellcheckcomponent.xml","schema.xml");
     //Index something with a title
     assertNull(h.validateUpdate(adoc("id", "0", "teststop", "This is a title")));
     assertNull(h.validateUpdate(adoc("id", "1", "teststop", "The quick reb fox jumped over the lazy brown dogs.")));
     assertNull(h.validateUpdate(adoc("id", "2", "teststop", "This is a Solr")));
     assertNull(h.validateUpdate(adoc("id", "3", "teststop", "solr foo")));
+    assertNull(h.validateUpdate(adoc("id", "4", "teststop", "another foo")));
     assertNull(h.validateUpdate(commit()));
     queryConverter = new SimpleQueryConverter();
     queryConverter.init(new NamedList());
@@ -77,4 +82,15 @@ public class DirectSolrSpellCheckerTest 
     assertTrue("suggestions is not null and it should be", suggestions == null);
     searcher.decref();
   }
+  
+  @Test
+  public void testOnlyMorePopularWithExtendedResults() throws Exception {
+  	assertQ(req("q", "teststop:fox", "qt", "spellCheckCompRH", SpellCheckComponent.COMPONENT_NAME, "true", SpellCheckComponent.SPELLCHECK_DICT, "direct", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true", SpellCheckComponent.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
+        "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='fox']/int[@name='origFreq']=1",
+        "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='fox']/arr[@name='suggestion']/lst/str[@name='word']='foo'",
+        "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='fox']/arr[@name='suggestion']/lst/int[@name='freq']=2",
+        "//lst[@name='spellcheck']/lst[@name='suggestions']/bool[@name='correctlySpelled']='true'"
+  	);
+  }  
+  
 }