use of org.apache.lucene.analysis.util.ResourceLoader in project lucene-solr by apache.
the class TestKeepFilterFactory method testInform.
public void testInform() throws Exception {
ResourceLoader loader = new ClasspathResourceLoader(getClass());
assertTrue("loader is null and it shouldn't be", loader != null);
KeepWordFilterFactory factory = (KeepWordFilterFactory) tokenFilterFactory("KeepWord", "words", "keep-1.txt", "ignoreCase", "true");
CharArraySet words = factory.getWords();
assertTrue("words is null and it shouldn't be", words != null);
assertTrue("words Size: " + words.size() + " is not: " + 2, words.size() == 2);
factory = (KeepWordFilterFactory) tokenFilterFactory("KeepWord", "words", "keep-1.txt, keep-2.txt", "ignoreCase", "true");
words = factory.getWords();
assertTrue("words is null and it shouldn't be", words != null);
assertTrue("words Size: " + words.size() + " is not: " + 4, words.size() == 4);
}
use of org.apache.lucene.analysis.util.ResourceLoader in project lucene-solr by apache.
the class TestCommonGramsFilterFactory method testInform.
public void testInform() throws Exception {
ResourceLoader loader = new ClasspathResourceLoader(TestStopFilterFactory.class);
assertTrue("loader is null and it shouldn't be", loader != null);
CommonGramsFilterFactory factory = (CommonGramsFilterFactory) tokenFilterFactory("CommonGrams", Version.LATEST, loader, "words", "stop-1.txt", "ignoreCase", "true");
CharArraySet words = factory.getCommonWords();
assertTrue("words is null and it shouldn't be", words != null);
assertTrue("words Size: " + words.size() + " is not: " + 2, words.size() == 2);
assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory.isIgnoreCase() == true);
factory = (CommonGramsFilterFactory) tokenFilterFactory("CommonGrams", Version.LATEST, loader, "words", "stop-1.txt, stop-2.txt", "ignoreCase", "true");
words = factory.getCommonWords();
assertTrue("words is null and it shouldn't be", words != null);
assertTrue("words Size: " + words.size() + " is not: " + 4, words.size() == 4);
assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory.isIgnoreCase() == true);
factory = (CommonGramsFilterFactory) tokenFilterFactory("CommonGrams", Version.LATEST, loader, "words", "stop-snowball.txt", "format", "snowball", "ignoreCase", "true");
words = factory.getCommonWords();
assertEquals(8, words.size());
assertTrue(words.contains("he"));
assertTrue(words.contains("him"));
assertTrue(words.contains("his"));
assertTrue(words.contains("himself"));
assertTrue(words.contains("she"));
assertTrue(words.contains("her"));
assertTrue(words.contains("hers"));
assertTrue(words.contains("herself"));
}
use of org.apache.lucene.analysis.util.ResourceLoader in project lucene-solr by apache.
the class TestCommonGramsQueryFilterFactory method testInform.
public void testInform() throws Exception {
ResourceLoader loader = new ClasspathResourceLoader(TestStopFilterFactory.class);
assertTrue("loader is null and it shouldn't be", loader != null);
CommonGramsQueryFilterFactory factory = (CommonGramsQueryFilterFactory) tokenFilterFactory("CommonGramsQuery", Version.LATEST, loader, "words", "stop-1.txt", "ignoreCase", "true");
CharArraySet words = factory.getCommonWords();
assertTrue("words is null and it shouldn't be", words != null);
assertTrue("words Size: " + words.size() + " is not: " + 2, words.size() == 2);
assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory.isIgnoreCase() == true);
factory = (CommonGramsQueryFilterFactory) tokenFilterFactory("CommonGramsQuery", Version.LATEST, loader, "words", "stop-1.txt, stop-2.txt", "ignoreCase", "true");
words = factory.getCommonWords();
assertTrue("words is null and it shouldn't be", words != null);
assertTrue("words Size: " + words.size() + " is not: " + 4, words.size() == 4);
assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory.isIgnoreCase() == true);
factory = (CommonGramsQueryFilterFactory) tokenFilterFactory("CommonGramsQuery", Version.LATEST, loader, "words", "stop-snowball.txt", "format", "snowball", "ignoreCase", "true");
words = factory.getCommonWords();
assertEquals(8, words.size());
assertTrue(words.contains("he"));
assertTrue(words.contains("him"));
assertTrue(words.contains("his"));
assertTrue(words.contains("himself"));
assertTrue(words.contains("she"));
assertTrue(words.contains("her"));
assertTrue(words.contains("hers"));
assertTrue(words.contains("herself"));
}
use of org.apache.lucene.analysis.util.ResourceLoader 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.ResourceLoader in project lucene-solr by apache.
the class TestSystemIdResolver method testResolving.
public void testResolving() throws Exception {
final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
final ResourceLoader loader = new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
final SystemIdResolver resolver = new SystemIdResolver(loader);
final String fileUri = new File(testHome + "/crazy-path-to-config.xml").toURI().toASCIIString();
assertEquals("solrres:/test.xml", SystemIdResolver.createSystemIdFromResourceName("test.xml"));
assertEquals("solrres://@/usr/local/etc/test.xml", SystemIdResolver.createSystemIdFromResourceName("/usr/local/etc/test.xml"));
assertEquals("solrres://@/test.xml", SystemIdResolver.createSystemIdFromResourceName(File.separatorChar + "test.xml"));
// check relative URI resolving
assertEquals("solrres:/test.xml", resolver.resolveRelativeURI("solrres:/base.xml", "test.xml").toASCIIString());
assertEquals("solrres://@/etc/test.xml", resolver.resolveRelativeURI("solrres://@/usr/local/etc/base.xml", "../../../etc/test.xml").toASCIIString());
// special case: if relative URI starts with "/" convert to an absolute solrres://@/-URI
assertEquals("solrres://@/a/test.xml", resolver.resolveRelativeURI("solrres:/base.xml", "/a/test.xml").toASCIIString());
// test, that resolving works if somebody uses an absolute file:-URI in a href attribute, it should be preserved
assertEquals(fileUri, resolver.resolveRelativeURI("solrres:/base.xml", fileUri).toASCIIString());
assertEquals("solrres:/base.xml", resolver.resolveRelativeURI(fileUri, "solrres:/base.xml").toASCIIString());
// do some real resolves to InputStreams with real existing files
assertEntityResolving(resolver, "solrres:/schema.xml", "solrres:/solrconfig.xml", "schema.xml");
assertEntityResolving(resolver, "solrres:/org/apache/solr/util/TestSystemIdResolver.class", "solrres:/org/apache/solr/util/RTimer.class", "TestSystemIdResolver.class");
assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome + "/collection1/conf/schema.xml"), SystemIdResolver.createSystemIdFromResourceName(testHome + "/collection1/conf/solrconfig.xml"), "schema.xml");
assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome + "/crazy-path-to-schema.xml"), SystemIdResolver.createSystemIdFromResourceName(testHome + "/crazy-path-to-config.xml"), "crazy-path-to-schema.xml");
// test, that resolving works if somebody uses an absolute file:-URI in a href attribute, the resolver should return null (default fallback)
assertNull(resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", fileUri));
}
Aggregations