Lucene Version : 4.4.0

SITUATION :

I need to suggest terms to the user based on a query prefix typed in a
textbox. The terms suggested should exist in the index that will be
searched. I want to suggest terms from more than one field in the
index.

I am trying to use
org.apache.lucene.search.suggest.analyzing.AnalyzingSuggester for
this.

PROBLEM :

Given the path to the index directory, I proceed as follows.
---------------------------------------------------------------
IndexReader ireader = DirectoryReader.open(FSDirectory.open(new
File(indexPath)));
List<AtomicReaderContext> readercs = ireader.leaves();
for (AtomicReaderContext readerc : readercs) {
    Fields fields = readerc.reader().fields();
    for (String field : fields) {
        TermsEnum termsEnum = fields.terms(field).iterator(null);
        tfit = new TermFreqIteratorWrapper(termsEnum);  // OVERWRITE!
    }
}
AnalyzingSuggester suggr = new AnalyzingSuggester(analyzer);
suggr.build(tfit);
---------------------------------------------------------------

In the line marked "OVERWRITE!", I am overwriting the term list from
one field with the term list from the next field. I want to aggregate
term lists obtained from different fields.

I could not find a way to instantiate TermFreqIterator without a
BytesRefIterator. The only way to get a BytesRefIterator seems to be
in the form of TermsEnum. Neither can be changed (i.e. appended to)
after instantiation.

How can I aggregate the TermsEnum lists from different fields so that
I can pass them together in one shot to build()? Alternatively, is
there a way to add term lists to the suggester after calling build()
once?

Thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to