Example usage for org.apache.lucene.search.suggest.analyzing AnalyzingInfixSuggester close

List of usage examples for org.apache.lucene.search.suggest.analyzing AnalyzingInfixSuggester close

Introduction

In this page you can find the example usage for org.apache.lucene.search.suggest.analyzing AnalyzingInfixSuggester close.

Prototype

@Override
    public void close() throws IOException 

Source Link

Usage

From source file:net.tourbook.search.FTSearchManager.java

License:Open Source License

public static void close() {

    if (_suggester instanceof AnalyzingInfixSuggester) {
        try {/*from  w ww.  j  a v  a 2 s .co m*/
            final AnalyzingInfixSuggester suggester = (AnalyzingInfixSuggester) _suggester;
            suggester.close();
        } catch (final IOException e) {
            StatusUtil.showStatus(e);
        }
    }
    _suggester = null;

    if (_indexReader != null) {

        try {

            _indexReader.close();
            _indexReader = null;

        } catch (final IOException e) {
            StatusUtil.showStatus(e);
        }
    }

    if (_infixStore != null) {
        _infixStore.close();
        _infixStore = null;
    }

}

From source file:org.lukhnos.lucenestudy.Suggester.java

License:MIT License

/**
 * Rebuild a suggestion index from the document index.
 *
 * This method iterates through the entire document index and makes sure that only unique titles
 * are indexed.//from   w w  w .j  av  a 2 s  .  c om
 *
 * @param indexRoot The parent directory inside which both the document index and the suggestion
 *                  index lives.
 * @throws IOException
 */
public static void rebuild(String indexRoot) throws IOException {
    Path indexRootPath = Paths.get(indexRoot);
    Path suggestionPath = getSuggestionIndexPath(indexRootPath);

    // Delete the suggestion index if it exists.
    if (Files.exists(suggestionPath)) {
        Util.deletePath(suggestionPath);
    }

    // Create the suggestion index.
    Analyzer analyzer = Indexer.getAnalyzer();
    Directory suggestionDir = FSDirectory.open(getSuggestionIndexPath(indexRootPath));
    AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(suggestionDir, analyzer);

    // Open the document index.
    Directory indexDir = FSDirectory.open(Indexer.getMainIndexPath(indexRootPath));
    IndexReader reader = DirectoryReader.open(indexDir);

    // Get a document iterator.
    DocumentDictionary docDict = new DocumentDictionary(reader, Indexer.TITLE_FIELD_NAME, null);
    InputIterator iterator = docDict.getEntryIterator();
    Set<BytesRef> titleSet = new HashSet<>();
    BytesRef next;
    while ((next = iterator.next()) != null) {
        if (titleSet.contains(next)) {
            continue;
        }

        titleSet.add(next);
        suggester.add(next, null, 0, null);
    }

    reader.close();

    suggester.commit();
    suggester.close();
}