@@ -290,21 +290,7 @@ class QueryInfo
290
290
std::string m_querySuffix;
291
291
};
292
292
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 ;
308
294
309
295
#if defined(LIBZIM_WITH_XAPIAN) && ! defined(_WIN32)
310
296
#define ENABLE_SPELLINGSDB
@@ -408,7 +394,7 @@ TermCollection getTermCompletions(const SuggestionDataBase& db,
408
394
return TermCollection ();
409
395
}
410
396
411
- const TermCollection allTerms = getAllTerms (db );
397
+ const TermCollection& allTerms = db. getAllSuggestionTerms ( );
412
398
auto it = std::lower_bound (allTerms.begin (), allTerms.end (),
413
399
TermWithFreq{termPrefix, 0 },
414
400
TermWithFreq::dictionaryPred);
@@ -427,7 +413,7 @@ std::vector<std::string> getSpellingCorrections(const SuggestionDataBase& db,
427
413
{
428
414
#ifdef ENABLE_SPELLINGSDB
429
415
if ( db.hasDatabase () ) {
430
- const TermCollection allTerms = getAllTerms (db );
416
+ const TermCollection& allTerms = db. getAllSuggestionTerms ( );
431
417
const SpellingsDB sdb (allTerms);
432
418
return sdb.getSpellingCorrections (word, maxCount);
433
419
}
@@ -438,6 +424,15 @@ std::vector<std::string> getSpellingCorrections(const SuggestionDataBase& db,
438
424
439
425
} // unnamed namespace
440
426
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
+
441
436
SuggestionSearch::Results SuggestionSearch::getAutocompletionSuggestions (uint32_t maxCount) const {
442
437
QueryInfo queryInfo (removeAccents (m_query));
443
438
0 commit comments