From 9196479a70c061e2a7d0d24cb14a910b1efd62ec Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 7 Feb 2024 17:34:08 +0100 Subject: [PATCH] Correcly search for book's title with double quote ("). At indexation time, double quote are ignored, so a title as `TED "talks" - Business` is indexed as `ted talks business`. By removing the quotes, we ensure that our title "phrase" is not closed too early and we correctly search for `ted PHRASE talks PHRASE business` instead of `ted AND talks AND business`. --- src/library.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/library.cpp b/src/library.cpp index ce26220ee..6ba046ec9 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -191,6 +191,16 @@ void Library::cleanupBookCollection(BookIdCollection& books, const std::string& } } +std::string remove_quote(std::string input) { + size_t lower_bound = 0; + size_t found = std::string::npos; + while ((found = input.find("\"", lower_bound)) != std::string::npos) { + input.erase(found, 1); + lower_bound = found; + } + return input; +} + std::string Library::getBestTargetBookId(const Bookmark& bookmark, MigrationMode migrationMode) const { // Search for a existing book with the same name auto book_filter = Filter(); @@ -203,7 +213,7 @@ std::string Library::getBestTargetBookId(const Bookmark& bookmark, MigrationMode // No bookName nor bookTitle, no way to find target book. return ""; } - book_filter.query("title:\""+bookmark.getBookTitle() + "\""); + book_filter.query("title:\"" + remove_quote(bookmark.getBookTitle()) + "\""); } auto targetBooks = filter(book_filter); cleanupBookCollection(targetBooks, bookmark.getBookId(), migrationMode);