lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1145442 - in /lucene/dev/trunk/solr/core/src: java/org/apache/solr/analysis/FSTSynonymFilterFactory.java test/org/apache/solr/analysis/TestSynonymFilterFactory.java
Date Tue, 12 Jul 2011 03:46:38 GMT
Author: rmuir
Date: Tue Jul 12 03:46:37 2011
New Revision: 1145442

URL: http://svn.apache.org/viewvc?rev=1145442&view=rev
Log:
LUCENE-3233: log a warning instead of error, if synonyms rule set is completely empty

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/analysis/FSTSynonymFilterFactory.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestSynonymFilterFactory.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/analysis/FSTSynonymFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/analysis/FSTSynonymFilterFactory.java?rev=1145442&r1=1145441&r2=1145442&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/analysis/FSTSynonymFilterFactory.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/analysis/FSTSynonymFilterFactory.java
Tue Jul 12 03:46:37 2011
@@ -56,7 +56,9 @@ final class FSTSynonymFilterFactory exte
   
   @Override
   public TokenStream create(TokenStream input) {
-    return new SynonymFilter(input, map, ignoreCase);
+    // if the fst is null, it means there's actually no synonyms... just return the original
stream
+    // as there is nothing to do here.
+    return map.fst == null ? input : new SynonymFilter(input, map, ignoreCase);
   }
 
   @Override
@@ -91,6 +93,10 @@ final class FSTSynonymFilterFactory exte
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
+    
+    if (map.fst == null) {
+      log.warn("Synonyms loaded with " + args + " has empty rule set!");
+    }
   }
   
   /**

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestSynonymFilterFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestSynonymFilterFactory.java?rev=1145442&r1=1145441&r2=1145442&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestSynonymFilterFactory.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/analysis/TestSynonymFilterFactory.java
Tue Jul 12 03:46:37 2011
@@ -17,14 +17,19 @@ package org.apache.solr.analysis;
  * limitations under the License.
  */
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringReader;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.lucene.analysis.MockTokenizer;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.synonym.SynonymFilter;
 import org.apache.lucene.util.Version;
+import org.apache.solr.common.ResourceLoader;
 import org.apache.solr.core.SolrResourceLoader;
 
 public class TestSynonymFilterFactory extends BaseTokenTestCase {
@@ -59,4 +64,36 @@ public class TestSynonymFilterFactory ex
         new String[] { "GB", "gib", "gigabyte", "gigabytes" },
         new int[] { 1, 0, 0, 0 });
   }
+  
+  /** if the synonyms are completely empty, test that we still analyze correctly */
+  public void testEmptySynonyms() throws Exception {
+    SynonymFilterFactory factory = new SynonymFilterFactory();
+    Map<String,String> args = new HashMap<String,String>();
+    args.putAll(DEFAULT_VERSION_PARAM);
+    args.put("synonyms", "synonyms.txt");
+    factory.init(args);
+    factory.inform(new StringMockSolrResourceLoader("")); // empty file!
+    TokenStream ts = factory.create(new MockTokenizer(new StringReader("GB"), MockTokenizer.WHITESPACE,
false));
+    assertTokenStreamContents(ts, new String[] { "GB" });
+  }
+  
+  private class StringMockSolrResourceLoader implements ResourceLoader {
+    String text;
+
+    StringMockSolrResourceLoader(String text) {
+      this.text = text;
+    }
+
+    public List<String> getLines(String resource) throws IOException {
+      return null;
+    }
+
+    public Object newInstance(String cname, String... subpackages) {
+      return null;
+    }
+
+    public InputStream openResource(String resource) throws IOException {
+      return new ByteArrayInputStream(text.getBytes("UTF-8"));
+    }
+  }
 }



Mime
View raw message