mirror of https://github.com/apache/lucene.git
LUCENE-3233: log a warning instead of error, if synonyms rule set is completely empty
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1145442 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b3671752f2
commit
2d9e65f34b
|
@ -56,7 +56,9 @@ final class FSTSynonymFilterFactory extends BaseTokenFilterFactory implements Re
|
|||
|
||||
@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 extends BaseTokenFilterFactory implements Re
|
|||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (map.fst == null) {
|
||||
log.warn("Synonyms loaded with " + args + " has empty rule set!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 extends BaseTokenTestCase {
|
|||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue