Link Search Menu Expand Document
Start for Free

Search Analyzers

This page describes how to create your own Search Analyzer for Stardog’s Full Text Search.

Page Contents
  1. Overview
  2. Implementing a Search Analyzer
  3. Example Search Analyzer
  4. Registering the Search Analyzer

Overview

By default, the full-text index in Stardog uses Lucene’s StandardAnalyzer

Implementing a Search Analyzer

Any class implementing org.apache.lucene.analysis.Analyzer can be used in place of the default analyzer described above. To specify a different Analyzer a service named com.complexible.stardog.search.AnalyzerFactory should be registered. AnalyzerFactory returns the desired Analyzer implementation to be used when creating the Lucene index from the RDF contained in the database.

Example Search Analyzer

This is an example of an AnalyzerFactory which uses the built-in Lucene analyzer for the French language:

public final class FrenchAnalyzerFactory implements AnalyzerFactory {

    @Override
    public Analyzer get() {
        return new FrenchAnalyzer(Version.LUCENE_47);
    }
}

Any of the common Lucene Analyzers can be used as well as any custom implementation of Analyzer. In the latter case, be sure your implementation is in Stardog’s class path.

Registering the Search Analyzer

Create a file called com.complexible.stardog.search.AnalyzerFactory in the META-INF/services directory. The contents of this file should be the fully-qualified class name of your AnalyzerFactory.

Further instructions for registering a service are provided in the title page of this chapter.

Only one AnalyzerFactory can be registered at a time, attempts to register more than one will yield errors on startup.