use of org.apache.lucene.analysis.util.AbstractAnalysisFactory in project lucene-solr by apache.
the class TestFactories method doTestTokenFilter.
private void doTestTokenFilter(String tokenfilter) throws IOException {
Class<? extends TokenFilterFactory> factoryClazz = TokenFilterFactory.lookupClass(tokenfilter);
TokenFilterFactory factory = (TokenFilterFactory) initialize(factoryClazz);
if (factory != null) {
// if it implements MultiTermAware, sanity check its impl
if (factory instanceof MultiTermAwareComponent) {
AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
assertNotNull(mtc);
// it's not ok to return a charfilter or tokenizer here, this makes no sense
assertTrue(mtc instanceof TokenFilterFactory);
}
// beast it just a little, it shouldnt throw exceptions:
// (it should have thrown them in initialize)
Analyzer a = new FactoryAnalyzer(assertingTokenizer, factory, null);
checkRandomData(random(), a, 20, 20, false, false);
a.close();
}
}
use of org.apache.lucene.analysis.util.AbstractAnalysisFactory in project lucene-solr by apache.
the class TestFactories method doTestTokenizer.
private void doTestTokenizer(String tokenizer) throws IOException {
Class<? extends TokenizerFactory> factoryClazz = TokenizerFactory.lookupClass(tokenizer);
TokenizerFactory factory = (TokenizerFactory) initialize(factoryClazz);
if (factory != null) {
// if it implements MultiTermAware, sanity check its impl
if (factory instanceof MultiTermAwareComponent) {
AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
assertNotNull(mtc);
// it's not ok to return e.g. a charfilter here: but a tokenizer could wrap a filter around it
assertFalse(mtc instanceof CharFilterFactory);
}
// beast it just a little, it shouldnt throw exceptions:
// (it should have thrown them in initialize)
Analyzer a = new FactoryAnalyzer(factory, null, null);
checkRandomData(random(), a, 20, 20, false, false);
a.close();
}
}
use of org.apache.lucene.analysis.util.AbstractAnalysisFactory in project lucene-solr by apache.
the class TestFactories method initialize.
/** tries to initialize a factory with no arguments */
private AbstractAnalysisFactory initialize(Class<? extends AbstractAnalysisFactory> factoryClazz) throws IOException {
Map<String, String> args = new HashMap<>();
args.put("luceneMatchVersion", Version.LATEST.toString());
Constructor<? extends AbstractAnalysisFactory> ctor;
try {
ctor = factoryClazz.getConstructor(Map.class);
} catch (Exception e) {
throw new RuntimeException("factory '" + factoryClazz + "' does not have a proper ctor!");
}
AbstractAnalysisFactory factory = null;
try {
factory = ctor.newInstance(args);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof IllegalArgumentException) {
// it's ok if we dont provide the right parameters to throw this
return null;
}
}
if (factory instanceof ResourceLoaderAware) {
try {
((ResourceLoaderAware) factory).inform(new StringMockResourceLoader(""));
} catch (IOException ignored) {
// it's ok if the right files arent available or whatever to throw this
} catch (IllegalArgumentException ignored) {
// is this ok? I guess so
}
}
return factory;
}
use of org.apache.lucene.analysis.util.AbstractAnalysisFactory in project lucene-solr by apache.
the class TestFactories method doTestTokenizer.
private void doTestTokenizer(String tokenizer) throws IOException {
Class<? extends TokenizerFactory> factoryClazz = TokenizerFactory.lookupClass(tokenizer);
TokenizerFactory factory = (TokenizerFactory) initialize(factoryClazz);
if (factory != null) {
// if it implements MultiTermAware, sanity check its impl
if (factory instanceof MultiTermAwareComponent) {
AbstractAnalysisFactory mtc = ((MultiTermAwareComponent) factory).getMultiTermComponent();
assertNotNull(mtc);
// it's not ok to return e.g. a charfilter here: but a tokenizer could wrap a filter around it
assertFalse(mtc instanceof CharFilterFactory);
}
// beast it just a little, it shouldnt throw exceptions:
// (it should have thrown them in initialize)
Analyzer a = new FactoryAnalyzer(factory, null, null);
checkRandomData(random(), a, 20, 20, false, false);
a.close();
}
}
use of org.apache.lucene.analysis.util.AbstractAnalysisFactory in project lucene-solr by apache.
the class TestFactories method initialize.
/** tries to initialize a factory with no arguments */
private AbstractAnalysisFactory initialize(Class<? extends AbstractAnalysisFactory> factoryClazz) throws IOException {
Map<String, String> args = new HashMap<>();
args.put("luceneMatchVersion", Version.LATEST.toString());
Constructor<? extends AbstractAnalysisFactory> ctor;
try {
ctor = factoryClazz.getConstructor(Map.class);
} catch (Exception e) {
throw new RuntimeException("factory '" + factoryClazz + "' does not have a proper ctor!");
}
AbstractAnalysisFactory factory = null;
try {
factory = ctor.newInstance(args);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof IllegalArgumentException) {
// it's ok if we dont provide the right parameters to throw this
return null;
}
}
if (factory instanceof ResourceLoaderAware) {
try {
((ResourceLoaderAware) factory).inform(new StringMockResourceLoader(""));
} catch (IOException ignored) {
// it's ok if the right files arent available or whatever to throw this
} catch (IllegalArgumentException ignored) {
// is this ok? I guess so
}
}
return factory;
}
Aggregations