Class ReversedWildcardFilterFactory

java.lang.Object
org.apache.lucene.analysis.AbstractAnalysisFactory
org.apache.lucene.analysis.TokenFilterFactory
org.apache.solr.analysis.ReversedWildcardFilterFactory

public class ReversedWildcardFilterFactory extends org.apache.lucene.analysis.TokenFilterFactory
Factory for ReversedWildcardFilter-s. When this factory is added to an analysis chain, it will be used both for filtering the tokens during indexing, and to determine the query processing of this field during search.

This class supports the following init arguments:

  • withOriginal - if true, then produce both original and reversed tokens at the same positions. If false, then produce only reversed tokens.
  • maxPosAsterisk - maximum position (1-based) of the asterisk wildcard ('*') that triggers the reversal of query term. Asterisk that occurs at positions higher than this value will not cause the reversal of query term. Defaults to 2, meaning that asterisks on positions 1 and 2 will cause a reversal.
  • maxPosQuestion - maximum position (1-based) of the question mark wildcard ('?') that triggers the reversal of query term. Defaults to 1. Set this to 0, and maxPosAsterisk to 1 to reverse only pure suffix queries (i.e. ones with a single leading asterisk).
  • maxFractionAsterisk - additional parameter that triggers the reversal if asterisk ('*') position is less than this fraction of the query token length. Defaults to 0.0f (disabled).
  • minTrailing - minimum number of trailing characters in query token after the last wildcard character. For good performance this should be set to a value larger than 1. Defaults to 2.
Note 1: This filter always reverses input tokens during indexing. Note 2: Query tokens without wildcard characters will never be reversed.
 <fieldType name="text_rvswc" class="solr.TextField" positionIncrementGap="100">
   <analyzer type="index">
     <tokenizer class="solr.WhitespaceTokenizerFactory"/>
     <filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
             maxPosAsterisk="2" maxPosQuestion="1" minTrailing="2" maxFractionAsterisk="0"/>
   </analyzer>
   <analyzer type="query">
     <tokenizer class="solr.WhitespaceTokenizerFactory"/>
   </analyzer>
 </fieldType>
Since:
3.1
SPI Name (case-insensitive: if the name is 'htmlStrip', 'htmlstrip' can be used when looking up the service).
"reversedWildcard"
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    SPI name

    Fields inherited from class org.apache.lucene.analysis.AbstractAnalysisFactory

    LUCENE_MATCH_VERSION_PARAM, luceneMatchVersion
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default ctor for compatibility with SPI
    Creates a new ReversedWildcardFilterFactory
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.lucene.analysis.TokenStream
    create(org.apache.lucene.analysis.TokenStream input)
     
    char
     
    boolean
    This method encapsulates the logic that determines whether a query token should be reversed in order to use the reversed terms in the index.

    Methods inherited from class org.apache.lucene.analysis.TokenFilterFactory

    availableTokenFilters, findSPIName, forName, lookupClass, normalize, reloadTokenFilters

    Methods inherited from class org.apache.lucene.analysis.AbstractAnalysisFactory

    defaultCtorException, get, get, get, get, get, getBoolean, getChar, getClassArg, getFloat, getInt, getLines, getLuceneMatchVersion, getOriginalArgs, getPattern, getSet, getSnowballWordSet, getWordSet, isExplicitLuceneMatchVersion, require, require, require, requireBoolean, requireChar, requireFloat, requireInt, setExplicitLuceneMatchVersion, splitAt, splitFileNames

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ReversedWildcardFilterFactory

      public ReversedWildcardFilterFactory(Map<String,String> args)
      Creates a new ReversedWildcardFilterFactory
    • ReversedWildcardFilterFactory

      public ReversedWildcardFilterFactory()
      Default ctor for compatibility with SPI
  • Method Details

    • create

      public org.apache.lucene.analysis.TokenStream create(org.apache.lucene.analysis.TokenStream input)
      Specified by:
      create in class org.apache.lucene.analysis.TokenFilterFactory
    • shouldReverse

      public boolean shouldReverse(String token)
      This method encapsulates the logic that determines whether a query token should be reversed in order to use the reversed terms in the index.
      Parameters:
      token - input token.
      Returns:
      true if input token should be reversed, false otherwise.
    • getMarkerChar

      public char getMarkerChar()