Class PerFieldAnalyzerWrapper

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class PerFieldAnalyzerWrapper
    extends AnalyzerWrapper
    This analyzer is used to facilitate scenarios where different fields require different analysis techniques. Use the Map argument in PerFieldAnalyzerWrapper(Analyzer, java.util.Map) to add non-default analyzers for fields.

    Example usage:

     
     Map<String,Analyzer> analyzerPerField = new HashMap<String,Analyzer>();
     analyzerPerField.put("firstname", new KeywordAnalyzer());
     analyzerPerField.put("lastname", new KeywordAnalyzer());
    
     PerFieldAnalyzerWrapper aWrapper =
       new PerFieldAnalyzerWrapper(new StandardAnalyzer(version), analyzerPerField);
     
     

    In this example, StandardAnalyzer will be used for all fields except "firstname" and "lastname", for which KeywordAnalyzer will be used.

    A PerFieldAnalyzerWrapper can be used like any other analyzer, for both indexing and query parsing.

    • Constructor Detail

      • PerFieldAnalyzerWrapper

        public PerFieldAnalyzerWrapper​(Analyzer defaultAnalyzer)
        Constructs with default analyzer.
        Parameters:
        defaultAnalyzer - Any fields not specifically defined to use a different analyzer will use the one provided here.
      • PerFieldAnalyzerWrapper

        public PerFieldAnalyzerWrapper​(Analyzer defaultAnalyzer,
                                       java.util.Map<java.lang.String,​Analyzer> fieldAnalyzers)
        Constructs with default analyzer and a map of analyzers to use for specific fields.
        Parameters:
        defaultAnalyzer - Any fields not specifically defined to use a different analyzer will use the one provided here.
        fieldAnalyzers - a Map (String field name to the Analyzer) to be used for those fields
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object