Class AnalyzerWrapper

    • Constructor Detail

      • AnalyzerWrapper

        protected AnalyzerWrapper​(Analyzer.ReuseStrategy reuseStrategy)
        Creates a new AnalyzerWrapper with the given reuse strategy.

        If you want to wrap a single delegate Analyzer you can probably reuse its strategy when instantiating this subclass: super(delegate.getReuseStrategy());.

        If you choose different analyzers per field, use Analyzer.PER_FIELD_REUSE_STRATEGY.

        See Also:
        Analyzer.getReuseStrategy()
    • Method Detail

      • getWrappedAnalyzer

        protected abstract Analyzer getWrappedAnalyzer​(String fieldName)
        Retrieves the wrapped Analyzer appropriate for analyzing the field with the given name
        Parameters:
        fieldName - Name of the field which is to be analyzed
        Returns:
        Analyzer for the field with the given name. Assumed to be non-null
      • wrapComponents

        protected Analyzer.TokenStreamComponents wrapComponents​(String fieldName,
                                                                Analyzer.TokenStreamComponents components)
        Wraps / alters the given TokenStreamComponents, taken from the wrapped Analyzer, to form new components. It is through this method that new TokenFilters can be added by AnalyzerWrappers. By default, the given components are returned.
        Parameters:
        fieldName - Name of the field which is to be analyzed
        components - TokenStreamComponents taken from the wrapped Analyzer
        Returns:
        Wrapped / altered TokenStreamComponents.
      • wrapTokenStreamForNormalization

        protected TokenStream wrapTokenStreamForNormalization​(String fieldName,
                                                              TokenStream in)
        Wraps / alters the given TokenStream for normalization purposes, taken from the wrapped Analyzer, to form new components. It is through this method that new TokenFilters can be added by AnalyzerWrappers. By default, the given token stream are returned.
        Parameters:
        fieldName - Name of the field which is to be analyzed
        in - TokenStream taken from the wrapped Analyzer
        Returns:
        Wrapped / altered TokenStreamComponents.
      • wrapReader

        protected Reader wrapReader​(String fieldName,
                                    Reader reader)
        Wraps / alters the given Reader. Through this method AnalyzerWrappers can implement initReader(String, Reader). By default, the given reader is returned.
        Parameters:
        fieldName - name of the field which is to be analyzed
        reader - the reader to wrap
        Returns:
        the wrapped reader
      • wrapReaderForNormalization

        protected Reader wrapReaderForNormalization​(String fieldName,
                                                    Reader reader)
        Wraps / alters the given Reader. Through this method AnalyzerWrappers can implement initReaderForNormalization(String, Reader). By default, the given reader is returned.
        Parameters:
        fieldName - name of the field which is to be analyzed
        reader - the reader to wrap
        Returns:
        the wrapped reader
      • getPositionIncrementGap

        public int getPositionIncrementGap​(String fieldName)
        Description copied from class: Analyzer
        Invoked before indexing a IndexableField instance if terms have already been added to that field. This allows custom analyzers to place an automatic position increment gap between IndexbleField instances using the same field name. The default value position increment gap is 0. With a 0 position increment gap and the typical default token position increment of 1, all terms in a field, including across IndexableField instances, are in successive positions, allowing exact PhraseQuery matches, for instance, across IndexableField instance boundaries.
        Overrides:
        getPositionIncrementGap in class Analyzer
        Parameters:
        fieldName - IndexableField name being indexed.
        Returns:
        position increment gap, added to the next token emitted from Analyzer.tokenStream(String,Reader). This value must be >= 0.
      • initReader

        public final Reader initReader​(String fieldName,
                                       Reader reader)
        Description copied from class: Analyzer
        Override this if you want to add a CharFilter chain.

        The default implementation returns reader unchanged.

        Overrides:
        initReader in class Analyzer
        Parameters:
        fieldName - IndexableField name being indexed
        reader - original Reader
        Returns:
        reader, optionally decorated with CharFilter(s)