@@ -290,7 +290,10 @@ class QueryInfo
290
290
std::string m_querySuffix;
291
291
};
292
292
293
- using namespace suggestions ;
293
+ } // unnamed namespace
294
+
295
+ namespace suggestions
296
+ {
294
297
295
298
#if defined(LIBZIM_WITH_XAPIAN) && ! defined(_WIN32)
296
299
#define ENABLE_SPELLINGSDB
@@ -361,6 +364,15 @@ std::vector<std::string> SpellingsDB::getSpellingCorrections(const std::string&
361
364
}
362
365
#endif // ENABLE_SPELLINGSDB
363
366
367
+ } // namespace suggestions
368
+
369
+ SuggestionDataBase::~SuggestionDataBase () = default ;
370
+
371
+ namespace
372
+ {
373
+
374
+ using namespace suggestions ;
375
+
364
376
bool isXapianTermPrefix (unsigned char c) {
365
377
return ' A' <= c && c <= ' Z' ;
366
378
}
@@ -407,23 +419,26 @@ TermCollection getTermCompletions(const SuggestionDataBase& db,
407
419
return result;
408
420
}
409
421
410
- std::vector<std::string> getSpellingCorrections (const SuggestionDataBase& db,
422
+ } // unnamed namespace
423
+
424
+ std::vector<std::string> SuggestionDataBase::getSpellingCorrections (
411
425
const std::string& word,
412
- uint32_t maxCount)
426
+ uint32_t maxCount) const
413
427
{
414
428
#ifdef ENABLE_SPELLINGSDB
415
- if ( db.hasDatabase () ) {
416
- const TermCollection& allTerms = db.getAllSuggestionTerms ();
417
- const SpellingsDB sdb (allTerms);
418
- return sdb.getSpellingCorrections (word, maxCount);
429
+ if ( this ->hasDatabase () ) {
430
+ std::lock_guard<std::mutex> locker (m_spellingsDBMutex);
431
+ if ( !m_spellingsDB ) {
432
+ const TermCollection& allTerms = this ->getAllSuggestionTerms ();
433
+ m_spellingsDB.reset (new SpellingsDB (allTerms));
434
+ }
435
+ return m_spellingsDB->getSpellingCorrections (word, maxCount);
419
436
}
420
437
#endif // ENABLE_SPELLINGSDB
421
438
422
439
return {};
423
440
}
424
441
425
- } // unnamed namespace
426
-
427
442
const TermCollection& SuggestionDataBase::getAllSuggestionTerms () const
428
443
{
429
444
std::lock_guard<std::mutex> locker (m_suggestionTermsMutex);
@@ -459,7 +474,7 @@ SuggestionSearch::Results SuggestionSearch::getSpellingSuggestions(uint32_t maxC
459
474
460
475
SuggestionSearch::Results r;
461
476
if ( !queryInfo.wordBeingEdited ().empty () ) {
462
- const auto terms = getSpellingCorrections (*mp_internalDb, queryInfo.wordBeingEdited (), maxCount);
477
+ const auto terms = mp_internalDb-> getSpellingCorrections (queryInfo.wordBeingEdited (), maxCount);
463
478
464
479
for (const auto & t : terms) {
465
480
const auto suggestion = queryInfo.spellingSuggestion (t);
0 commit comments