Example usage for org.apache.lucene.analysis.util TokenFilterFactory isExplicitLuceneMatchVersion

List of usage examples for org.apache.lucene.analysis.util TokenFilterFactory isExplicitLuceneMatchVersion

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.util TokenFilterFactory isExplicitLuceneMatchVersion.

Prototype

public boolean isExplicitLuceneMatchVersion() 

Source Link

Usage

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

License:Apache License

/** 
 * Returns a description of the given analyzer, by either reporting the Analyzer name
 * if it's not a TokenizerChain, or if it is, querying each analysis factory for its
 * name and args.//from   w w w. j  av a  2s.  c o m
 */
protected static SimpleOrderedMap<Object> getAnalyzerProperties(Analyzer analyzer) {
    SimpleOrderedMap<Object> analyzerProps = new SimpleOrderedMap<Object>();

    if (analyzer instanceof TokenizerChain) {
        Map<String, String> factoryArgs;
        TokenizerChain tokenizerChain = (TokenizerChain) analyzer;
        CharFilterFactory[] charFilterFactories = tokenizerChain.getCharFilterFactories();
        if (null != charFilterFactories && charFilterFactories.length > 0) {
            List<SimpleOrderedMap<Object>> charFilterProps = new ArrayList<SimpleOrderedMap<Object>>();
            for (CharFilterFactory charFilterFactory : charFilterFactories) {
                SimpleOrderedMap<Object> props = new SimpleOrderedMap<Object>();
                props.add(CLASS_NAME, charFilterFactory.getClassArg());
                factoryArgs = charFilterFactory.getOriginalArgs();
                if (null != factoryArgs) {
                    for (String key : factoryArgs.keySet()) {
                        if (!CLASS_NAME.equals(key)) {
                            if (LUCENE_MATCH_VERSION_PARAM.equals(key)) {
                                if (charFilterFactory.isExplicitLuceneMatchVersion()) {
                                    props.add(key, factoryArgs.get(key));
                                }
                            } else {
                                props.add(key, factoryArgs.get(key));
                            }
                        }
                    }
                }
                charFilterProps.add(props);
            }
            analyzerProps.add(CHAR_FILTERS, charFilterProps);
        }

        SimpleOrderedMap<Object> tokenizerProps = new SimpleOrderedMap<Object>();
        TokenizerFactory tokenizerFactory = tokenizerChain.getTokenizerFactory();
        tokenizerProps.add(CLASS_NAME, tokenizerFactory.getClassArg());
        factoryArgs = tokenizerFactory.getOriginalArgs();
        if (null != factoryArgs) {
            for (String key : factoryArgs.keySet()) {
                if (!CLASS_NAME.equals(key)) {
                    if (LUCENE_MATCH_VERSION_PARAM.equals(key)) {
                        if (tokenizerFactory.isExplicitLuceneMatchVersion()) {
                            tokenizerProps.add(key, factoryArgs.get(key));
                        }
                    } else {
                        tokenizerProps.add(key, factoryArgs.get(key));
                    }
                }
            }
        }
        analyzerProps.add(TOKENIZER, tokenizerProps);

        TokenFilterFactory[] filterFactories = tokenizerChain.getTokenFilterFactories();
        if (null != filterFactories && filterFactories.length > 0) {
            List<SimpleOrderedMap<Object>> filterProps = new ArrayList<SimpleOrderedMap<Object>>();
            for (TokenFilterFactory filterFactory : filterFactories) {
                SimpleOrderedMap<Object> props = new SimpleOrderedMap<Object>();
                props.add(CLASS_NAME, filterFactory.getClassArg());
                factoryArgs = filterFactory.getOriginalArgs();
                if (null != factoryArgs) {
                    for (String key : factoryArgs.keySet()) {
                        if (!CLASS_NAME.equals(key)) {
                            if (LUCENE_MATCH_VERSION_PARAM.equals(key)) {
                                if (filterFactory.isExplicitLuceneMatchVersion()) {
                                    props.add(key, factoryArgs.get(key));
                                }
                            } else {
                                props.add(key, factoryArgs.get(key));
                            }
                        }
                    }
                }
                filterProps.add(props);
            }
            analyzerProps.add(FILTERS, filterProps);
        }
    } else { // analyzer is not instanceof TokenizerChain
        analyzerProps.add(CLASS_NAME, analyzer.getClass().getName());
    }
    return analyzerProps;
}