use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.
the class TestPhoneticFilterFactory method testUnknownEncoderReflection.
public void testUnknownEncoderReflection() throws IOException {
IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
Map<String, String> args = new HashMap<>();
args.put("encoder", "org.apache.commons.codec.language.NonExistence");
PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
factory.inform(new ClasspathResourceLoader(factory.getClass()));
});
assertTrue(expected.getMessage().contains("Error loading encoder"));
}
use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.
the class TestMorfologikFilterFactory method testExplicitDictionary.
public void testExplicitDictionary() throws Exception {
final ResourceLoader loader = new ClasspathResourceLoader(TestMorfologikFilterFactory.class);
StringReader reader = new StringReader("inflected1 inflected2");
Map<String, String> params = new HashMap<>();
params.put(MorfologikFilterFactory.DICTIONARY_ATTRIBUTE, "custom-dictionary.dict");
MorfologikFilterFactory factory = new MorfologikFilterFactory(params);
factory.inform(loader);
TokenStream stream = whitespaceMockTokenizer(reader);
stream = factory.create(stream);
assertTokenStreamContents(stream, new String[] { "lemma1", "lemma2" });
}
use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.
the class TestPhoneticFilterFactory method testFactoryDefaults.
/**
* Case: default
*/
public void testFactoryDefaults() throws IOException {
Map<String, String> args = new HashMap<>();
args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
factory.inform(new ClasspathResourceLoader(factory.getClass()));
assertTrue(factory.getEncoder() instanceof Metaphone);
// default
assertTrue(factory.inject);
}
use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.
the class TestPhoneticFilterFactory method testUnknownEncoder.
public void testUnknownEncoder() throws IOException {
IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
Map<String, String> args = new HashMap<>();
args.put("encoder", "XXX");
PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
factory.inform(new ClasspathResourceLoader(factory.getClass()));
});
assertTrue(expected.getMessage().contains("Error loading encoder"));
}
use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.
the class TestPhoneticFilterFactory method assertAlgorithm.
static void assertAlgorithm(String algName, String inject, String input, String[] expected) throws Exception {
Tokenizer tokenizer = whitespaceMockTokenizer(input);
Map<String, String> args = new HashMap<>();
args.put("encoder", algName);
args.put("inject", inject);
PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
factory.inform(new ClasspathResourceLoader(factory.getClass()));
TokenStream stream = factory.create(tokenizer);
assertTokenStreamContents(stream, expected);
}
Aggregations