List<String> dummy = new ArrayList<>();
for (File aSpellIndex : spellIndex) {
if (!aSpellIndex.exists()) {
continue;
}
SpellChecker checker = null;
Suggestion s = new Suggestion(aSpellIndex.getName());
try (FSDirectory spellDirectory = FSDirectory.open(aSpellIndex)) {
checker = new SpellChecker(spellDirectory);
getSuggestion(builder.getFreetext(), checker, dummy);
s.freetext = dummy.toArray(new String[dummy.size()]);
dummy.clear();
getSuggestion(builder.getRefs(), checker, dummy);
s.refs = dummy.toArray(new String[dummy.size()]);
dummy.clear();
// TODO it seems the only true spellchecker is for
// below field, see IndexDatabase
// createspellingsuggestions ...
getSuggestion(builder.getDefs(), checker, dummy);
s.defs = dummy.toArray(new String[dummy.size()]);
dummy.clear();
if (s.freetext.length > 0 || s.defs.length > 0 || s.refs.length > 0) {
res.add(s);
}
} catch (IOException e) {
log.log(Level.WARNING, "Got excption while getting spelling suggestions: ", e);
} finally {
if (checker != null) {
try {
checker.close();
} catch (Exception x) {
log.log(Level.WARNING, "Got excption while closing spelling suggestions: ", x);
}
}
}