List of usage examples for org.apache.lucene.search.suggest.analyzing FreeTextSuggester FreeTextSuggester
public FreeTextSuggester(Analyzer analyzer)
From source file:spimedb.SpimeDB.java
License:Apache License
@Nullable private Lookup suggester() { Lookup suggester = this.suggester; if (suggester == null || lastWrite - lastSuggesterCreated > minSuggesterUpdatePeriod) { suggester = null; //re-create since it is invalidated Lock l = locker.lock("_suggester"); try {//from w w w . ja va 2 s . c om if (this.suggester != null) return this.suggester; //created while waiting for the lock FreeTextSuggester nextSuggester = new FreeTextSuggester(new SimpleAnalyzer()); read((nameDictReader) -> { if (nameDictReader.maxDoc() == 0) return; DocumentDictionary nameDict = new DocumentDictionary(nameDictReader, NObject.NAME, NObject.NAME); Stopwatch time = Stopwatch.createStarted(); try { nextSuggester.build(nameDict); } catch (IOException f) { logger.error("suggester build {}", f); } this.suggester = nextSuggester; lastSuggesterCreated = now(); logger.info("suggester built size={} {}ms", nextSuggester.getCount(), time.elapsed(MILLISECONDS)); //time.reset(); // FacetsCollector fc = new FacetsCollector(); // FacetsCollector.search(new IndexSearcher(nameDictReader), new MatchAllDocsQuery(), Integer.MAX_VALUE, // fc // ); // logger.info("facets updated, count={} {}ms", fc., time.elapsed(MILLISECONDS)); }); return this.suggester; } finally { l.unlock(); } } else { return suggester; } }