diff --git a/include/name_mapper.h b/include/name_mapper.h index 4247c5c3..8b8bde62 100644 --- a/include/name_mapper.h +++ b/include/name_mapper.h @@ -54,6 +54,7 @@ class HumanReadableNameMapper : public NameMapper { virtual ~HumanReadableNameMapper() = default; virtual std::string getNameForId(const std::string& id) const; virtual std::string getIdForName(const std::string& name) const; + static std::string removeDateFromBookId(const std::string& bookId); }; class UpdatableNameMapper : public NameMapper { diff --git a/src/library.cpp b/src/library.cpp index 1bc36090..7b0db077 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -28,6 +28,7 @@ #include "tools/stringTools.h" #include "tools/otherTools.h" #include "tools/concurrent_cache.h" +#include "name_mapper.h" #include #include @@ -462,7 +463,7 @@ void Library::updateBookDB(const Book& book) indexer.index_text(normalizeText(book.getName()), 1, "XN"); indexer.index_text(normalizeText(book.getCategory()), 1, "XC"); const auto bookName = book.getHumanReadableIdFromPath(); - const auto aliasName = replaceRegex(bookName, "", "_[[:digit:]]{4}-[[:digit:]]{2}$"); + const auto aliasName = HumanReadableNameMapper::removeDateFromBookId(bookName); indexer.index_text(normalizeText(aliasName), 1, "XF"); for ( const auto& tag : split(normalizeText(book.getTags()), ";") ) { diff --git a/src/name_mapper.cpp b/src/name_mapper.cpp index dccf40c9..6877e229 100644 --- a/src/name_mapper.cpp +++ b/src/name_mapper.cpp @@ -34,7 +34,7 @@ HumanReadableNameMapper::HumanReadableNameMapper(kiwix::Library& library, bool w if (!withAlias) continue; - auto aliasName = replaceRegex(bookName, "", "_[[:digit:]]{4}-[[:digit:]]{2}$"); + auto aliasName = removeDateFromBookId(bookName); if (aliasName == bookName) { continue; } @@ -51,6 +51,10 @@ HumanReadableNameMapper::HumanReadableNameMapper(kiwix::Library& library, bool w } } +std::string HumanReadableNameMapper::removeDateFromBookId(const std::string& bookId) { + return replaceRegex(bookId, "", "_[[:digit:]]{4}-[[:digit:]]{2}$"); +} + std::string HumanReadableNameMapper::getNameForId(const std::string& id) const { return m_idToName.at(id); }