Muppenz
Muppenz

Reputation: 85

Generating dictionary from a directory (for Lucene autocomplete)

Using Lucene 4.9 (Java), I've been looking for a way to implement an autocomplete/suggest feature. The goal is to use several of the fields data used in my indexed documents as the source of the dictionary. What is the best practice or suggested way of generating a dictionary based on this?

I tried LuceneDirectory, but the issue is that it only accepts one field, shown below:

LuceneDictionary ld = new LuceneDictionary(indexReader, "fieldname");

What i'm looking for is something similar to this, but with a possibility of being able to supply an array of string with fields to populate my dictionary.

My next step was to look at the source of the class of LuceneDirectory, hoping to make my own custom Dictionary class implementing the Lucene directory interface. This however, was outside of my scope, and I was hoping someone else might have already done an implementation of this, or know how I can proceed.

To summarize:

1: How do I create a dictionary from an existing directory, with data from multiple fields(terms)?

2: How do I keep the dictionary updated once it has been created? Should I regenerate it on a regular basis or are there any other best practices for this?

Upvotes: 1

Views: 662

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

You can add multiple Dictionaries to a SpellChecker, like:

SpellChecker spellchecker = new SpellChecker(spellIndexDirectory);
spellchecker.indexDictionary(new LuceneDictionary(indexReader, "fieldname"));
spellchecker.indexDictionary(new LuceneDictionary(indexReader, "anotherfield"));

Upvotes: 1

Related Questions