Search in sources :

Example 16 with TokenizerChain

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

the class FieldTypePluginLoader method constructMultiTermAnalyzer.

// The point here is that, if no multiterm analyzer was specified in the schema file, do one of several things:
// 1> If legacyMultiTerm == false, assemble a new analyzer composed of all of the charfilters,
//    lowercase filters and asciifoldingfilter.
// 2> If legacyMultiTerm == true just construct the analyzer from a KeywordTokenizer. That should mimic current behavior.
//    Do the same if they've specified that the old behavior is required (legacyMultiTerm="true")
private Analyzer constructMultiTermAnalyzer(Analyzer queryAnalyzer) {
    if (queryAnalyzer == null)
        return null;
    if (!(queryAnalyzer instanceof TokenizerChain)) {
        return new KeywordAnalyzer();
    }
    TokenizerChain tc = (TokenizerChain) queryAnalyzer;
    MultiTermChainBuilder builder = new MultiTermChainBuilder();
    CharFilterFactory[] charFactories = tc.getCharFilterFactories();
    for (CharFilterFactory fact : charFactories) {
        builder.add(fact);
    }
    builder.add(tc.getTokenizerFactory());
    for (TokenFilterFactory fact : tc.getTokenFilterFactories()) {
        builder.add(fact);
    }
    return builder.build();
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) TokenizerChain(org.apache.solr.analysis.TokenizerChain) CharFilterFactory(org.apache.lucene.analysis.util.CharFilterFactory) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory)

Example 17 with TokenizerChain

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

the class PayloadUtils method getPayloadEncoder.

public static String getPayloadEncoder(FieldType fieldType) {
    // TODO: support custom payload encoding fields too somehow - maybe someone has a custom component that encodes payloads as floats
    String encoder = null;
    Analyzer a = fieldType.getIndexAnalyzer();
    if (a instanceof TokenizerChain) {
        // examine the indexing analysis chain for DelimitedPayloadTokenFilterFactory or NumericPayloadTokenFilterFactory
        TokenizerChain tc = (TokenizerChain) a;
        TokenFilterFactory[] factories = tc.getTokenFilterFactories();
        for (TokenFilterFactory factory : factories) {
            if (factory instanceof DelimitedPayloadTokenFilterFactory) {
                encoder = factory.getOriginalArgs().get(DelimitedPayloadTokenFilterFactory.ENCODER_ATTR);
                break;
            }
            if (factory instanceof NumericPayloadTokenFilterFactory) {
                // encodes using `PayloadHelper.encodeFloat(payload)`
                encoder = "float";
                break;
            }
        }
    }
    return encoder;
}
Also used : TokenizerChain(org.apache.solr.analysis.TokenizerChain) DelimitedPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory) Analyzer(org.apache.lucene.analysis.Analyzer) NumericPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.NumericPayloadTokenFilterFactory) DelimitedPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory) NumericPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.NumericPayloadTokenFilterFactory) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory)

Aggregations

TokenizerChain (org.apache.solr.analysis.TokenizerChain)17 TokenFilterFactory (org.apache.lucene.analysis.util.TokenFilterFactory)15 Analyzer (org.apache.lucene.analysis.Analyzer)10 CharFilterFactory (org.apache.lucene.analysis.util.CharFilterFactory)7 TokenizerFactory (org.apache.lucene.analysis.util.TokenizerFactory)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 TokenStream (org.apache.lucene.analysis.TokenStream)3 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)3 KeywordTokenizerFactory (org.apache.lucene.analysis.core.KeywordTokenizerFactory)3 LowerCaseFilterFactory (org.apache.lucene.analysis.core.LowerCaseFilterFactory)3 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)3 StringReader (java.io.StringReader)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Tokenizer (org.apache.lucene.analysis.Tokenizer)2 ASCIIFoldingFilterFactory (org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilterFactory)2