Class PhoneticFilterFactory

  • All Implemented Interfaces:
    ResourceLoaderAware

    public class PhoneticFilterFactory
    extends TokenFilterFactory
    implements ResourceLoaderAware
    Factory for PhoneticFilter.

    Create tokens based on phonetic encoders from Apache Commons Codec.

    This takes one required argument, "encoder", and the rest are optional:

    encoder
    required, one of "DoubleMetaphone", "Metaphone", "Soundex", "RefinedSoundex", "Caverphone" (v2.0), "ColognePhonetic" or "Nysiis" (case insensitive). If encoder isn't one of these, it'll be resolved as a class name either by itself if it already contains a '.' or otherwise as in the same package as these others.
    inject
    (default=true) add tokens to the stream with the offset=0
    maxCodeLength
    The maximum length of the phonetic codes, as defined by the encoder. If an encoder doesn't support this then specifying this is an error.
     <fieldType name="text_phonetic" class="solr.TextField" positionIncrementGap="100">
       <analyzer>
         <tokenizer class="solr.WhitespaceTokenizerFactory"/>
         <filter class="solr.PhoneticFilterFactory" encoder="DoubleMetaphone" inject="true"/>
       </analyzer>
     </fieldType>
    Since:
    3.1
    See Also:
    PhoneticFilter
    • Field Detail

      • ENCODER

        public static final java.lang.String ENCODER
        parameter name: either a short name or a full class name
        See Also:
        Constant Field Values
      • INJECT

        public static final java.lang.String INJECT
        parameter name: true if encoded tokens should be added as synonyms
        See Also:
        Constant Field Values
      • MAX_CODE_LENGTH

        public static final java.lang.String MAX_CODE_LENGTH
        parameter name: restricts the length of the phonetic code
        See Also:
        Constant Field Values
      • PACKAGE_CONTAINING_ENCODERS

        private static final java.lang.String PACKAGE_CONTAINING_ENCODERS
        See Also:
        Constant Field Values
      • registry

        private static final java.util.Map<java.lang.String,​java.lang.Class<? extends org.apache.commons.codec.Encoder>> registry
      • inject

        final boolean inject
      • name

        private final java.lang.String name
      • maxCodeLength

        private final java.lang.Integer maxCodeLength
      • clazz

        private java.lang.Class<? extends org.apache.commons.codec.Encoder> clazz
      • setMaxCodeLenMethod

        private java.lang.reflect.Method setMaxCodeLenMethod
    • Constructor Detail

      • PhoneticFilterFactory

        public PhoneticFilterFactory​(java.util.Map<java.lang.String,​java.lang.String> args)
        Creates a new PhoneticFilterFactory
      • PhoneticFilterFactory

        public PhoneticFilterFactory()
        Default ctor for compatibility with SPI
    • Method Detail

      • inform

        public void inform​(ResourceLoader loader)
                    throws java.io.IOException
        Description copied from interface: ResourceLoaderAware
        Initializes this component with the provided ResourceLoader (used for loading classes, files, etc).
        Specified by:
        inform in interface ResourceLoaderAware
        Throws:
        java.io.IOException
      • resolveEncoder

        private java.lang.Class<? extends org.apache.commons.codec.Encoder> resolveEncoder​(java.lang.String name,
                                                                                           ResourceLoader loader)
      • getEncoder

        protected org.apache.commons.codec.Encoder getEncoder()
        Must be thread-safe.