Do not index book's name as a phrase.

Fix #1004
This commit is contained in:
Matthieu Gautier 2023-11-06 14:45:54 +01:00
parent e89f4e2ac7
commit 07ff4eab43
2 changed files with 29 additions and 8 deletions

View File

@ -436,7 +436,7 @@ void Library::updateBookDB(const Book& book)
} }
indexer.index_text(normalizeText(book.getCreator()), 1, "A"); indexer.index_text(normalizeText(book.getCreator()), 1, "A");
indexer.index_text(normalizeText(book.getPublisher()), 1, "XP"); 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"); indexer.index_text(normalizeText(book.getCategory()), 1, "XC");
for ( const auto& tag : split(normalizeText(book.getTags()), ";") ) { for ( const auto& tag : split(normalizeText(book.getTags()), ";") ) {

View File

@ -218,7 +218,7 @@ const char sampleLibraryXML[] = R"(
creator="Wikibooks" creator="Wikibooks"
publisher="Kiwix & Some Enthusiasts" publisher="Kiwix & Some Enthusiasts"
date="2021-04-11" date="2021-04-11"
name="wikibooks_de" name="wikibooks.de"
tags="unittest;wikibooks;_category:wikibooks" tags="unittest;wikibooks;_category:wikibooks"
articleCount="12" articleCount="12"
mediaCount="0" mediaCount="0"
@ -680,17 +680,38 @@ TEST_F(LibraryTest, filterByPublisher)
TEST_F(LibraryTest, filterByName) TEST_F(LibraryTest, filterByName)
{ {
EXPECT_FILTER_RESULTS(kiwix::Filter().name("wikibooks_de"), EXPECT_FILTER_RESULTS(kiwix::Filter().name("wikibooks.de"),
"An example ZIM archive" "An example ZIM archive"
); );
EXPECT_FILTER_RESULTS(kiwix::Filter().query("name:wikibooks_de"), // Parsing the query with `name:` prefix splits the token on the dot, as if it was 2 sentences.
"An example ZIM archive" // It creates a query "XNwikibook@1 PHRASE 2 XNde@2".
); // I haven't found the syntax to not split on dot.
EXPECT_FILTER_RESULTS(kiwix::Filter().query("name:wikibooks.de"),
EXPECT_FILTER_RESULTS(kiwix::Filter().query("wikibooks_de"),
/* no results */ /* no results */
); );
EXPECT_FILTER_RESULTS(kiwix::Filter().name("wikibooks"),
/* no results */
);
// Wikibooks is in `tags` so it matches.
EXPECT_FILTER_RESULTS(kiwix::Filter().query("wikibooks"),
"An example ZIM archive"
);
// But "wikibooks.de" is only in name and `query` doesn't looks in name.
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) TEST_F(LibraryTest, filterByCategory)