Search in sources :

Example 1 with LuceneDictionary

use of org.apache.lucene.search.spell.LuceneDictionary in project jackrabbit-oak by apache.

the class SuggestHelper method updateSuggester.

public static void updateSuggester(Directory directory, Analyzer analyzer, IndexReader reader) throws IOException {
    File tempDir = null;
    try {
        //Analyzing infix suggester takes a file parameter. It uses its path to getDirectory()
        //for actual storage of suggester data. BUT, while building it also does getDirectory() to
        //a temporary location (original path + ".tmp"). So, instead we create a temp dir and also
        //create a placeholder non-existing-sub-child which would mark the location when we want to return
        //our internal suggestion OakDirectory. After build is done, we'd delete the temp directory
        //thereby removing any temp stuff that suggester created in the interim.
        tempDir = Files.createTempDir();
        File tempSubChild = new File(tempDir, "non-existing-sub-child");
        if (reader.getDocCount(FieldNames.SUGGEST) > 0) {
            Dictionary dictionary = new LuceneDictionary(reader, FieldNames.SUGGEST);
            getLookup(directory, analyzer, tempSubChild).build(dictionary);
        }
    } catch (RuntimeException e) {
        log.debug("could not update the suggester", e);
    } finally {
        //cleanup temp dir
        if (tempDir != null && !FileUtils.deleteQuietly(tempDir)) {
            log.error("Cleanup failed for temp dir {}", tempDir.getAbsolutePath());
        }
    }
}
Also used : LuceneDictionary(org.apache.lucene.search.spell.LuceneDictionary) Dictionary(org.apache.lucene.search.spell.Dictionary) LuceneDictionary(org.apache.lucene.search.spell.LuceneDictionary) File(java.io.File)

Aggregations

File (java.io.File)1 Dictionary (org.apache.lucene.search.spell.Dictionary)1 LuceneDictionary (org.apache.lucene.search.spell.LuceneDictionary)1