Skip to content

Commit

Permalink
Correcly search for book's title with double quote (").
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
mgautierfr committed Feb 7, 2024
1 parent e50e149 commit 9196479
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 9196479

Please sign in to comment.