From 9785fdb8729781a0ebb1727a8a8531b6ea9f1ccb Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 6 Nov 2023 14:45:54 +0100 Subject: [PATCH] Do not index book's name as a phrase. Fix #1004 --- src/library.cpp | 2 +- test/library.cpp | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 702bf8bdd..98482d87d 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -436,7 +436,7 @@ void Library::updateBookDB(const Book& book) } indexer.index_text(normalizeText(book.getCreator()), 1, "A"); indexer.index_text(normalizeText(book.getPublisher()), 1, "XP"); - indexer.index_text(normalizeText(book.getName()), 1, "XN"); + doc.add_term("XN"+normalizeText(book.getName())); indexer.index_text(normalizeText(book.getCategory()), 1, "XC"); for ( const auto& tag : split(normalizeText(book.getTags()), ";") ) { diff --git a/test/library.cpp b/test/library.cpp index 30a77fcff..79346f168 100644 --- a/test/library.cpp +++ b/test/library.cpp @@ -218,7 +218,7 @@ const char sampleLibraryXML[] = R"( creator="Wikibooks" publisher="Kiwix & Some Enthusiasts" date="2021-04-11" - name="wikibooks_de" + name="wikibooks.de" tags="unittest;wikibooks;_category:wikibooks" articleCount="12" mediaCount="0" @@ -680,17 +680,32 @@ TEST_F(LibraryTest, filterByPublisher) TEST_F(LibraryTest, filterByName) { - EXPECT_FILTER_RESULTS(kiwix::Filter().name("wikibooks_de"), + EXPECT_FILTER_RESULTS(kiwix::Filter().name("wikibooks.de"), "An example ZIM archive" ); - EXPECT_FILTER_RESULTS(kiwix::Filter().query("name:wikibooks_de"), - "An example ZIM archive" + // Parsing the query with `name:` prefix splits the token on the dot, as if it was 2 sentences. + // It creates a query "XNwikibook@1 PHRASE 2 XNde@2". + // I haven't found the syntax to no split on dot + EXPECT_FILTER_RESULTS(kiwix::Filter().query("name:wikibooks.de"), + /* no results */ + ); + + EXPECT_FILTER_RESULTS(kiwix::Filter().name("wikibooks"), + /* no results */ ); EXPECT_FILTER_RESULTS(kiwix::Filter().query("wikibooks_de"), /* no results */ ); + + EXPECT_FILTER_RESULTS(kiwix::Filter().name("wikipedia_en_ray_charles"), + "Ray Charles" + ); + + EXPECT_FILTER_RESULTS(kiwix::Filter().query("name:wikipedia_en_ray_charles"), + "Ray Charles" + ); } TEST_F(LibraryTest, filterByCategory)