4.5.4. @AnalyzerDef for Solr


When using Maven all required Apache Solr dependencies are now defined as dependencies of the artifact org.hibernate:hibernate-search-analyzers. Add the following dependency:
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-search-analyzers</artifactId>
   <version>${version.hibernate.search}</version>
<dependency>
Copy to Clipboard Toggle word wrap
In the following example, a CharFilter is defined by its factory. In this example, a mapping char filter is used, which will replace characters in the input based on the rules specified in the mapping file. Finally, a list of filters is defined by their factories. In this example, the StopFilter filter is built reading the dedicated words property file. The filter will ignore case.

Procedure 4.2. @AnalyzerDef and the Solr framework

  1. Configure the CharFilter

    Define a CharFilter by factory. In this example, a mapping CharFilter is used, which will replace characters in the input based on the rules specified in the mapping file.
    @AnalyzerDef(name="customanalyzer",
      charFilters = {
        @CharFilterDef(factory = MappingCharFilterFactory.class, params = {
          @Parameter(name = "mapping",
            value = "org/hibernate/search/test/analyzer/solr/mapping-chars.properties")
        })
      },
    
    
    Copy to Clipboard Toggle word wrap
  2. Define the Tokenizer

    A Tokenizer is then defined using the StandardTokenizerFactory.class.
    @AnalyzerDef(name="customanalyzer",
      charFilters = {
        @CharFilterDef(factory = MappingCharFilterFactory.class, params = {
          @Parameter(name = "mapping",
            value = "org/hibernate/search/test/analyzer/solr/mapping-chars.properties")
        })
      },
      
      tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class)
    
    Copy to Clipboard Toggle word wrap
  3. List of Filters

    Define a list of filters by their factories. In this example, the StopFilter filter is built reading the dedicated words property file. The filter will ignore case.
    @AnalyzerDef(name="customanalyzer",
      charFilters = {
        @CharFilterDef(factory = MappingCharFilterFactory.class, params = {
          @Parameter(name = "mapping",
            value = "org/hibernate/search/test/analyzer/solr/mapping-chars.properties")
        })
      },
      
      tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
      filters = {
                     
        @TokenFilterDef(factory = ISOLatin1AccentFilterFactory.class),
        @TokenFilterDef(factory = LowerCaseFilterFactory.class),
        @TokenFilterDef(factory = StopFilterFactory.class, params = {
          @Parameter(name="words",
            value= "org/hibernate/search/test/analyzer/solr/stoplist.properties" ),
          @Parameter(name="ignoreCase", value="true")
        })
    })public class Team {
        ...}
    
    Copy to Clipboard Toggle word wrap

Note

Filters and CharFilters are applied in the order they are defined in the @AnalyzerDef annotation.
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat