Class ProtectedTermFilterFactory

  • All Implemented Interfaces:
    ResourceLoaderAware

    public class ProtectedTermFilterFactory
    extends ConditionalTokenFilterFactory
    Factory for a ProtectedTermFilter

    CustomAnalyzer example:

     Analyzer ana = CustomAnalyzer.builder()
       .withTokenizer("standard")
       .when("protectedterm", "ignoreCase", "true", "protected", "protectedTerms.txt")
         .addTokenFilter("truncate", "prefixLength", "4")
         .addTokenFilter("lowercase")
       .endwhen()
       .build();
     

    Solr example, in which conditional filters are specified via the wrappedFilters parameter - a comma-separated list of case-insensitive TokenFilter SPI names - and conditional filter args are specified via filterName.argName parameters:

     <fieldType name="reverse_lower_with_exceptions" class="solr.TextField" positionIncrementGap="100">
       <analyzer>
         <tokenizer class="solr.WhitespaceTokenizerFactory"/>
         <filter class="solr.ProtectedTermFilterFactory" ignoreCase="true" protected="protectedTerms.txt"
                 wrappedFilters="truncate,lowercase" truncate.prefixLength="4" />
       </analyzer>
     </fieldType>

    When using the wrappedFilters parameter, each filter name must be unique, so if you need to specify the same filter more than once, you must add case-insensitive unique '-id' suffixes (note that the '-id' suffix is stripped prior to SPI lookup), e.g.:

     <fieldType name="double_synonym_with_exceptions" class="solr.TextField" positionIncrementGap="100">
       <analyzer>
         <tokenizer class="solr.WhitespaceTokenizerFactory"/>
         <filter class="solr.ProtectedTermFilterFactory" ignoreCase="true" protected="protectedTerms.txt"
                 wrappedFilters="synonymgraph-A,synonymgraph-B"
                 synonymgraph-A.synonyms="synonyms-1.txt"
                 synonymgraph-B.synonyms="synonyms-2.txt"/>
       </analyzer>
     </fieldType>

    See related CustomAnalyzer.Builder.whenTerm(Predicate)

    Since:
    7.4.0
    SPI Name (case-insensitive: if the name is 'htmlStrip', 'htmlstrip' can be used when looking up the service).
    "protectedTerm"