Class CustomAnalyzer.Builder

    • Method Detail

      • withDefaultMatchVersion

        public CustomAnalyzer.Builder withDefaultMatchVersion​(Version version)
        This match version is passed as default to all tokenizers or filters. It is used unless you pass the parameter {code luceneMatchVersion} explicitly. It defaults to undefined, so the underlying factory will (in most cases) use Version.LATEST.
      • withTokenizer

        public CustomAnalyzer.Builder withTokenizer​(java.lang.Class<? extends TokenizerFactory> factory,
                                                    java.lang.String... params)
                                             throws java.io.IOException
        Uses the given tokenizer.
        Parameters:
        factory - class that is used to create the tokenizer.
        params - a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.
        Throws:
        java.io.IOException
      • withTokenizer

        public CustomAnalyzer.Builder withTokenizer​(java.lang.Class<? extends TokenizerFactory> factory,
                                                    java.util.Map<java.lang.String,​java.lang.String> params)
                                             throws java.io.IOException
        Uses the given tokenizer.
        Parameters:
        factory - class that is used to create the tokenizer.
        params - the map of parameters to be passed to factory. The map must be modifiable.
        Throws:
        java.io.IOException
      • withTokenizer

        public CustomAnalyzer.Builder withTokenizer​(java.lang.String name,
                                                    java.lang.String... params)
                                             throws java.io.IOException
        Uses the given tokenizer.
        Parameters:
        name - is used to look up the factory with TokenizerFactory.forName(String, Map). The list of possible names can be looked up with TokenizerFactory.availableTokenizers().
        params - a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.
        Throws:
        java.io.IOException
      • withTokenizer

        public CustomAnalyzer.Builder withTokenizer​(java.lang.String name,
                                                    java.util.Map<java.lang.String,​java.lang.String> params)
                                             throws java.io.IOException
        Uses the given tokenizer.
        Parameters:
        name - is used to look up the factory with TokenizerFactory.forName(String, Map). The list of possible names can be looked up with TokenizerFactory.availableTokenizers().
        params - the map of parameters to be passed to factory. The map must be modifiable.
        Throws:
        java.io.IOException
      • addTokenFilter

        public CustomAnalyzer.Builder addTokenFilter​(java.lang.Class<? extends TokenFilterFactory> factory,
                                                     java.lang.String... params)
                                              throws java.io.IOException
        Adds the given token filter.
        Parameters:
        factory - class that is used to create the token filter.
        params - a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.
        Throws:
        java.io.IOException
      • addTokenFilter

        public CustomAnalyzer.Builder addTokenFilter​(java.lang.Class<? extends TokenFilterFactory> factory,
                                                     java.util.Map<java.lang.String,​java.lang.String> params)
                                              throws java.io.IOException
        Adds the given token filter.
        Parameters:
        factory - class that is used to create the token filter.
        params - the map of parameters to be passed to factory. The map must be modifiable.
        Throws:
        java.io.IOException
      • addTokenFilter

        public CustomAnalyzer.Builder addTokenFilter​(java.lang.String name,
                                                     java.lang.String... params)
                                              throws java.io.IOException
        Adds the given token filter.
        Parameters:
        name - is used to look up the factory with TokenFilterFactory.forName(String, Map). The list of possible names can be looked up with TokenFilterFactory.availableTokenFilters().
        params - a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.
        Throws:
        java.io.IOException
      • addCharFilter

        public CustomAnalyzer.Builder addCharFilter​(java.lang.Class<? extends CharFilterFactory> factory,
                                                    java.lang.String... params)
                                             throws java.io.IOException
        Adds the given char filter.
        Parameters:
        factory - class that is used to create the char filter.
        params - a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.
        Throws:
        java.io.IOException
      • addCharFilter

        public CustomAnalyzer.Builder addCharFilter​(java.lang.Class<? extends CharFilterFactory> factory,
                                                    java.util.Map<java.lang.String,​java.lang.String> params)
                                             throws java.io.IOException
        Adds the given char filter.
        Parameters:
        factory - class that is used to create the char filter.
        params - the map of parameters to be passed to factory. The map must be modifiable.
        Throws:
        java.io.IOException
      • addCharFilter

        public CustomAnalyzer.Builder addCharFilter​(java.lang.String name,
                                                    java.lang.String... params)
                                             throws java.io.IOException
        Adds the given char filter.
        Parameters:
        name - is used to look up the factory with CharFilterFactory.forName(String, Map). The list of possible names can be looked up with CharFilterFactory.availableCharFilters().
        params - a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.
        Throws:
        java.io.IOException
      • addCharFilter

        public CustomAnalyzer.Builder addCharFilter​(java.lang.String name,
                                                    java.util.Map<java.lang.String,​java.lang.String> params)
                                             throws java.io.IOException
        Adds the given char filter.
        Parameters:
        name - is used to look up the factory with CharFilterFactory.forName(String, Map). The list of possible names can be looked up with CharFilterFactory.availableCharFilters().
        params - the map of parameters to be passed to factory. The map must be modifiable.
        Throws:
        java.io.IOException
      • whenTerm

        public CustomAnalyzer.ConditionBuilder whenTerm​(java.util.function.Predicate<java.lang.CharSequence> predicate)
        Apply subsequent token filters if the current token's term matches a predicate This is the equivalent of:
           when(new ConditionalTokenFilterFactory(Collections.emptyMap()) {
              @Override
              protected ConditionalTokenFilter create(TokenStream input, Function<TokenStream, TokenStream> inner) {
                return new ConditionalTokenFilter(input, inner) {
                  CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
                  @Override
                  protected boolean shouldFilter() {
                    return predicate.test(termAtt);
                  }
                };
              }
           });
         
      • applyDefaultParams

        private java.util.Map<java.lang.String,​java.lang.String> applyDefaultParams​(java.util.Map<java.lang.String,​java.lang.String> map)
      • paramsToMap

        private java.util.Map<java.lang.String,​java.lang.String> paramsToMap​(java.lang.String... params)
      • applyResourceLoader

        <T> T applyResourceLoader​(T factory)
                           throws java.io.IOException
        Throws:
        java.io.IOException