mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #1016 from kiwix/fix_query_with_dot
Do not index book's name as a phrase.
This commit is contained in:
commit
37274f7882
|
@ -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()), ";") ) {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue