@@ -290,21 +290,7 @@ class QueryInfo
290290 std::string m_querySuffix;
291291};
292292
293- struct TermWithFreq
294- {
295- std::string term;
296- uint32_t freq;
297-
298- static bool freqPred (const TermWithFreq& t1, const TermWithFreq& t2) {
299- return t1.freq > t2.freq ;
300- }
301-
302- static bool dictionaryPred (const TermWithFreq& t1, const TermWithFreq& t2) {
303- return t1.term < t2.term ;
304- }
305- };
306-
307- typedef std::vector<TermWithFreq> TermCollection;
293+ using namespace suggestions ;
308294
309295#if defined(LIBZIM_WITH_XAPIAN) && ! defined(_WIN32)
310296#define ENABLE_SPELLINGSDB
@@ -408,7 +394,7 @@ TermCollection getTermCompletions(const SuggestionDataBase& db,
408394 return TermCollection ();
409395 }
410396
411- const TermCollection allTerms = getAllTerms (db );
397+ const TermCollection& allTerms = db. getAllSuggestionTerms ( );
412398 auto it = std::lower_bound (allTerms.begin (), allTerms.end (),
413399 TermWithFreq{termPrefix, 0 },
414400 TermWithFreq::dictionaryPred);
@@ -427,7 +413,7 @@ std::vector<std::string> getSpellingCorrections(const SuggestionDataBase& db,
427413{
428414#ifdef ENABLE_SPELLINGSDB
429415 if ( db.hasDatabase () ) {
430- const TermCollection allTerms = getAllTerms (db );
416+ const TermCollection& allTerms = db. getAllSuggestionTerms ( );
431417 const SpellingsDB sdb (allTerms);
432418 return sdb.getSpellingCorrections (word, maxCount);
433419 }
@@ -438,6 +424,15 @@ std::vector<std::string> getSpellingCorrections(const SuggestionDataBase& db,
438424
439425} // unnamed namespace
440426
427+ const TermCollection& SuggestionDataBase::getAllSuggestionTerms () const
428+ {
429+ std::lock_guard<std::mutex> locker (m_suggestionTermsMutex);
430+ if ( m_suggestionTerms.empty () ) {
431+ m_suggestionTerms = getAllTerms (*this );
432+ }
433+ return m_suggestionTerms;
434+ }
435+
441436SuggestionSearch::Results SuggestionSearch::getAutocompletionSuggestions (uint32_t maxCount) const {
442437 QueryInfo queryInfo (removeAccents (m_query));
443438
0 commit comments