Lucene Configuration
The LuceneContext provides configuration options for the Lucene index.
LuceneContext Factory Methods
// Embedded storage (persisted with GigaMap)
LuceneContext<E> context = LuceneContext.New(documentPopulator);
// File system storage (MMapDirectory)
LuceneContext<E> context = LuceneContext.New(directoryPath, documentPopulator);
// Custom directory creator
LuceneContext<E> context = LuceneContext.New(directoryCreator, documentPopulator);
// Full customization
LuceneContext<E> context = LuceneContext.New(directoryCreator, analyzerCreator, documentPopulator);
// Full customization including the commit behavior
LuceneContext<E> context = LuceneContext.New(directoryCreator, analyzerCreator, documentPopulator, autoCommit);
Directory Creators
The DirectoryCreator controls where index data is stored.
| Creator | Description | Use Case |
|---|---|---|
Embedded (default) |
Stores data inside the GigaMap object graph |
When you want the index persisted with your data |
|
Memory-mapped file storage |
Production environments, large indexes |
|
In-memory storage |
Testing, temporary indexes |
Embedded Storage
When no directory creator is specified, the index data is stored inside the GigaMap’s object graph. This means the index is automatically persisted when the GigaMap is stored with EclipseStore.
LuceneContext<Article> context = LuceneContext.New(
new ArticleDocumentPopulator()
);
MMap Directory
For large indexes or when you want separate storage, use memory-mapped file storage.
LuceneContext<Article> context = LuceneContext.New(
Paths.get("/data/lucene-index"),
new ArticleDocumentPopulator()
);
// Or explicitly
LuceneContext<Article> context = LuceneContext.New(
DirectoryCreator.MMap(Paths.get("/data/lucene-index")),
new ArticleDocumentPopulator()
);
Analyzer Creators
The AnalyzerCreator controls how text is tokenized and processed.
Standard Analyzer (Default)
The default analyzer tokenizes on word boundaries, removes common stopwords, and lowercases text.
// Uses StandardAnalyzer by default
LuceneContext<Article> context = LuceneContext.New(
new ArticleDocumentPopulator()
);
// Or explicitly
LuceneContext<Article> context = LuceneContext.New(
DirectoryCreator.ByteBuffers(),
AnalyzerCreator.Standard(),
new ArticleDocumentPopulator()
);
Custom Analyzer
For language-specific or domain-specific text processing, subclass AnalyzerCreator and override createAnalyzer().
StandardAnalyzer ships with lucene-core. Language-specific analyzers such as GermanAnalyzer live in lucene-analysis-common, which has to be added as an additional dependency.
|
public class GermanAnalyzerCreator extends AnalyzerCreator
{
@Override
public Analyzer createAnalyzer()
{
return new GermanAnalyzer();
}
}
LuceneContext<Article> context = LuceneContext.New(
DirectoryCreator.MMap(indexPath),
new GermanAnalyzerCreator(),
new ArticleDocumentPopulator()
);
Auto-Commit
By default, changes are automatically committed after each operation. For bulk operations, you may want to disable auto-commit for better performance. Pass the flag to the four-argument LuceneContext.New(…) factory.
With autoCommit disabled, pending changes are still committed automatically at every GigaMap.store() boundary, so an explicit LuceneIndex.commit() is only needed to commit between stores.
// Manual commit for bulk operations; null directory creator means embedded storage
LuceneContext<Article> context = LuceneContext.New(
null ,
AnalyzerCreator.Standard() ,
new ArticleDocumentPopulator() ,
false // autoCommit
);
GigaMap<Article> articles = GigaMap.New();
LuceneIndex<Article> luceneIndex = articles.index().register(LuceneIndex.Category(context));
// Add many entities
for (Article article : bulkArticles)
{
articles.add(article);
}
// Commit once at the end
luceneIndex.commit();