Defining a Lucene Index by Annotation

In addition to providing a DocumentPopulator and LuceneContext by hand (see Configuration), a Lucene full-text index can be declared with the @FullText annotation from the gigamap-lucene module.

Annotate the fields or no-argument getters that should be searchable:

public class Article
{
    @FullText
    private String title;

    @FullText(analyzed = true)   // tokenized full-text field (default)
    private String content;

    @FullText(analyzed = false)  // exact-match keyword field
    private String sku;
}
Attribute Meaning

name

Lucene document field name; defaults to the property name.

analyzed

true (default) indexes a tokenized TextField; false indexes an exact-match StringField.

store

Whether the original value is stored in the index (default true).

Register the LuceneAnnotationHandler with annotation-based generation and pass the GigaMap:

GigaMap<Article> gigaMap = GigaMap.New();
IndexerGenerator.AnnotationBased(Article.class)
    .register(LuceneAnnotationHandler.New())
    .generateIndices(gigaMap);

gigaMap.add(new Article(/* ... */));

LuceneIndex<Article> index = gigaMap.index().get(LuceneIndex.class);
List<Article> hits = index.query("title:eclipse");

By default the Lucene data is stored inside the GigaMap object graph. To store it in a directory instead, create the handler with a directory: LuceneAnnotationHandler.New(path) or LuceneAnnotationHandler.New(directoryCreator).

Like a manually registered Lucene index, an annotation-generated one is back-filled: if generateIndices runs on a GigaMap that already contains entities, those existing entities are indexed immediately, so generation can happen before or after the data is loaded.

The handler is a no-op when the entity type carries no @FullText member, so it composes safely with bitmap (@Index) and other annotations on the same entity. See Annotation-based Indexing for the overall model.