Example usage for org.apache.solr.schema FieldType getIndexAnalyzer

List of usage examples for org.apache.solr.schema FieldType getIndexAnalyzer

Introduction

In this page you can find the example usage for org.apache.solr.schema FieldType getIndexAnalyzer.

Prototype

public Analyzer getIndexAnalyzer() 

Source Link

Document

Returns the Analyzer to be used when indexing fields of this type.

Usage

From source file:com.ifactory.press.db.solr.processor.FieldMergingProcessorFactory.java

License:Apache License

private void doInit() {
    Object o = initArgs.get("destinationField");
    if (o == null || !(o instanceof String)) {
        log.error("destinationField must be present as a string, got " + o);
        return;/*from  w  ww  .  j  ava 2  s .c o  m*/
    }
    destinationField = (String) o;
    FieldType destinationFieldType = schema.getFieldType(destinationField);
    if (destinationFieldType == null) {
        log.error("deistinationField is not defined in the schema: it has no schema type");
        return;
    }
    o = initArgs.get("sourceField");
    if (o == null || !(o instanceof NamedList)) {
        log.error("sourceField must be present as a list, got " + o);
        return;
    }
    NamedList<?> sourceFields = (NamedList<?>) o;
    if (sourceFields.size() == 0) {
        log.error("destinationField must not be empty");
    }
    sourceAnalyzers = new HashMap<String, Analyzer>();
    for (int i = 0; i < sourceFields.size(); i++) {
        String sourceFieldName = sourceFields.getName(i);
        o = sourceFields.getVal(i);
        FieldType fieldType;
        if (o instanceof String && !((String) o).isEmpty()) {
            String analysisFieldName = (String) o;
            fieldType = schema.getFieldTypeByName(analysisFieldName);
            if (fieldType == null) {
                log.error("No such field type: " + analysisFieldName);
            }
        } else {
            fieldType = schema.getFieldType(sourceFieldName);
            if (fieldType == null) {
                log.error("No field type for field: " + sourceFieldName);
            }
        }
        if (fieldType != null) {
            sourceAnalyzers.put(sourceFieldName, fieldType.getIndexAnalyzer());
        }
    }

}

From source file:org.opensextant.solrtexttagger.TaggerRequestHandler.java

License:Open Source License

private boolean fieldHasIndexedStopFilter(String field, SolrQueryRequest req) {
    FieldType fieldType = req.getSchema().getFieldType(field);
    Analyzer analyzer = fieldType.getIndexAnalyzer();//index analyzer
    if (analyzer instanceof TokenizerChain) {
        TokenizerChain tokenizerChain = (TokenizerChain) analyzer;
        TokenFilterFactory[] tokenFilterFactories = tokenizerChain.getTokenFilterFactories();
        for (TokenFilterFactory tokenFilterFactory : tokenFilterFactories) {
            if (tokenFilterFactory instanceof StopFilterFactory)
                return true;
        }/* ww  w  .  j  a  v  a 2 s . c  om*/
    }
    return false;
}