Search in sources :

Example 1 with KeywordTokenizerFactory

use of org.apache.lucene.analysis.core.KeywordTokenizerFactory in project lucene-solr by apache.

the class MultiTermTest method testDefaultCopiedToMulti.

@Test
public void testDefaultCopiedToMulti() {
    SchemaField field = h.getCore().getLatestSchema().getField("content_ws");
    Analyzer analyzer = ((TextField) field.getType()).getMultiTermAnalyzer();
    assertTrue(analyzer instanceof TokenizerChain);
    assertTrue(((TokenizerChain) analyzer).getTokenizerFactory() instanceof KeywordTokenizerFactory);
    TokenizerChain tc = (TokenizerChain) analyzer;
    for (TokenFilterFactory factory : tc.getTokenFilterFactories()) {
        assertTrue((factory instanceof ASCIIFoldingFilterFactory) || (factory instanceof LowerCaseFilterFactory));
    }
    assertTrue(tc.getCharFilterFactories().length == 0);
}
Also used : TokenizerChain(org.apache.solr.analysis.TokenizerChain) ASCIIFoldingFilterFactory(org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory) LowerCaseFilterFactory(org.apache.lucene.analysis.core.LowerCaseFilterFactory) Analyzer(org.apache.lucene.analysis.Analyzer) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory) KeywordTokenizerFactory(org.apache.lucene.analysis.core.KeywordTokenizerFactory) Test(org.junit.Test)

Example 2 with KeywordTokenizerFactory

use of org.apache.lucene.analysis.core.KeywordTokenizerFactory in project lucene-solr by apache.

the class ResourceLoaderTest method testAwareCompatibility.

public void testAwareCompatibility() throws Exception {
    Class<?> clazz = ResourceLoaderAware.class;
    // Check ResourceLoaderAware valid objects
    assertAwareCompatibility(clazz, new NGramFilterFactory(new HashMap<>()));
    assertAwareCompatibility(clazz, new KeywordTokenizerFactory(new HashMap<>()));
    // Make sure it throws an error for invalid objects
    Object[] invalid = new Object[] { // new NGramTokenFilter( null ),
    "hello", new Float(12.3f), new LukeRequestHandler(), new JSONResponseWriter() };
    for (Object obj : invalid) {
        try {
            assertAwareCompatibility(clazz, obj);
            Assert.fail("Should be invalid class: " + obj + " FOR " + clazz);
        }// OK
         catch (SolrException ex) {
        }
    }
    clazz = SolrCoreAware.class;
    // Check ResourceLoaderAware valid objects
    assertAwareCompatibility(clazz, new LukeRequestHandler());
    assertAwareCompatibility(clazz, new FacetComponent());
    assertAwareCompatibility(clazz, new JSONResponseWriter());
    // Make sure it throws an error for invalid objects
    invalid = new Object[] { new NGramFilterFactory(new HashMap<>()), "hello", new Float(12.3f), new KeywordTokenizerFactory(new HashMap<>()) };
    for (Object obj : invalid) {
        try {
            assertAwareCompatibility(clazz, obj);
            Assert.fail("Should be invalid class: " + obj + " FOR " + clazz);
        }// OK
         catch (SolrException ex) {
        }
    }
}
Also used : JSONResponseWriter(org.apache.solr.response.JSONResponseWriter) HashMap(java.util.HashMap) FacetComponent(org.apache.solr.handler.component.FacetComponent) LukeRequestHandler(org.apache.solr.handler.admin.LukeRequestHandler) ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware) NGramFilterFactory(org.apache.lucene.analysis.ngram.NGramFilterFactory) SolrException(org.apache.solr.common.SolrException) KeywordTokenizerFactory(org.apache.lucene.analysis.core.KeywordTokenizerFactory)

Example 3 with KeywordTokenizerFactory

use of org.apache.lucene.analysis.core.KeywordTokenizerFactory in project lucene-solr by apache.

the class MultiTermTest method testQueryCopiedToMulti.

@Test
public void testQueryCopiedToMulti() {
    SchemaField field = h.getCore().getLatestSchema().getField("content_charfilter");
    Analyzer analyzer = ((TextField) field.getType()).getMultiTermAnalyzer();
    assertTrue(analyzer instanceof TokenizerChain);
    assertTrue(((TokenizerChain) analyzer).getTokenizerFactory() instanceof KeywordTokenizerFactory);
    TokenizerChain tc = (TokenizerChain) analyzer;
    for (TokenFilterFactory factory : tc.getTokenFilterFactories()) {
        assertTrue(factory instanceof LowerCaseFilterFactory);
    }
    assertTrue(tc.getCharFilterFactories().length == 1);
    assertTrue(tc.getCharFilterFactories()[0] instanceof MappingCharFilterFactory);
}
Also used : TokenizerChain(org.apache.solr.analysis.TokenizerChain) LowerCaseFilterFactory(org.apache.lucene.analysis.core.LowerCaseFilterFactory) MappingCharFilterFactory(org.apache.lucene.analysis.charfilter.MappingCharFilterFactory) Analyzer(org.apache.lucene.analysis.Analyzer) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory) KeywordTokenizerFactory(org.apache.lucene.analysis.core.KeywordTokenizerFactory) Test(org.junit.Test)

Aggregations

KeywordTokenizerFactory (org.apache.lucene.analysis.core.KeywordTokenizerFactory)3 Analyzer (org.apache.lucene.analysis.Analyzer)2 LowerCaseFilterFactory (org.apache.lucene.analysis.core.LowerCaseFilterFactory)2 TokenFilterFactory (org.apache.lucene.analysis.util.TokenFilterFactory)2 TokenizerChain (org.apache.solr.analysis.TokenizerChain)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 MappingCharFilterFactory (org.apache.lucene.analysis.charfilter.MappingCharFilterFactory)1 ASCIIFoldingFilterFactory (org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory)1 NGramFilterFactory (org.apache.lucene.analysis.ngram.NGramFilterFactory)1 ResourceLoaderAware (org.apache.lucene.analysis.util.ResourceLoaderAware)1 SolrException (org.apache.solr.common.SolrException)1 LukeRequestHandler (org.apache.solr.handler.admin.LukeRequestHandler)1 FacetComponent (org.apache.solr.handler.component.FacetComponent)1 JSONResponseWriter (org.apache.solr.response.JSONResponseWriter)1