Example usage for org.apache.lucene.analysis.core KeywordTokenizerFactory KeywordTokenizerFactory

List of usage examples for org.apache.lucene.analysis.core KeywordTokenizerFactory KeywordTokenizerFactory

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.core KeywordTokenizerFactory KeywordTokenizerFactory.

Prototype

public KeywordTokenizerFactory(Map<String, String> args) 

Source Link

Document

Creates a new KeywordTokenizerFactory

Usage

From source file:org.apache.solr.core.ResourceLoaderTest.java

License:Apache License

public void testAwareCompatibility() throws Exception {
    SolrResourceLoader loader = new SolrResourceLoader(".");

    Class<?> clazz = ResourceLoaderAware.class;
    // Check ResourceLoaderAware valid objects
    loader.assertAwareCompatibility(clazz, new NGramFilterFactory(new HashMap<String, String>()));
    loader.assertAwareCompatibility(clazz, new KeywordTokenizerFactory(new HashMap<String, String>()));

    // 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 {/*from w w  w  .  ja  v a  2s . c  o m*/
            loader.assertAwareCompatibility(clazz, obj);
            Assert.fail("Should be invalid class: " + obj + " FOR " + clazz);
        } catch (SolrException ex) {
        } // OK
    }

    clazz = SolrCoreAware.class;
    // Check ResourceLoaderAware valid objects
    loader.assertAwareCompatibility(clazz, new LukeRequestHandler());
    loader.assertAwareCompatibility(clazz, new FacetComponent());
    loader.assertAwareCompatibility(clazz, new JSONResponseWriter());

    // Make sure it throws an error for invalid objects
    invalid = new Object[] { new NGramFilterFactory(new HashMap<String, String>()), "hello", new Float(12.3f),
            new KeywordTokenizerFactory(new HashMap<String, String>()) };
    for (Object obj : invalid) {
        try {
            loader.assertAwareCompatibility(clazz, obj);
            Assert.fail("Should be invalid class: " + obj + " FOR " + clazz);
        } catch (SolrException ex) {
        } // OK
    }

    loader.close();
}

From source file:org.apache.solr.schema.CustomAnalyzerStrField.java

License:Apache License

public CustomAnalyzerStrField() {
    Random r = LuceneTestCase.random();

    // two arg constructor
    Analyzer a2 = new TokenizerChain(new KeywordTokenizerFactory(new HashMap<>()),
            r.nextBoolean() ? null : new TokenFilterFactory[0]);

    // three arg constructor
    Analyzer a3 = new TokenizerChain(r.nextBoolean() ? null : new CharFilterFactory[0],
            new KeywordTokenizerFactory(new HashMap<>()), r.nextBoolean() ? null : new TokenFilterFactory[0]);

    if (r.nextBoolean()) {
        indexAnalyzer = a2;//w ww .  j av  a2s .  co  m
        queryAnalyzer = a3;
    } else {
        queryAnalyzer = a2;
        indexAnalyzer = a3;
    }
}