From 39732e2bcfcac4e5d8ae3fadf81bf5651b9cd1c2 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:07:46 +0100 Subject: [PATCH 1/7] Deprecate methods on Book. - `update(const Reader& reader)` is replaced by `update(const zim::Archive& archive)` - `getFavicon*()` is replaced by `getIllustration(48)->*` --- include/book.h | 9 +++++---- src/libxml_dumper.cpp | 11 +++++++---- test/book.cpp | 13 ++++++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/book.h b/include/book.h index f0ac10aea..ce228d19a 100644 --- a/include/book.h +++ b/include/book.h @@ -24,6 +24,7 @@ #include #include #include +#include "common.h" namespace pugi { class xml_node; @@ -68,7 +69,7 @@ class Book ~Book(); bool update(const Book& other); - void update(const Reader& reader); + DEPRECATED void update(const Reader& reader); void update(const zim::Archive& archive); void updateFromXml(const pugi::xml_node& node, const std::string& baseDir); void updateFromOpds(const pugi::xml_node& node, const std::string& urlHost); @@ -95,9 +96,9 @@ class Book const uint64_t& getArticleCount() const { return m_articleCount; } const uint64_t& getMediaCount() const { return m_mediaCount; } const uint64_t& getSize() const { return m_size; } - const std::string& getFavicon() const; - const std::string& getFaviconUrl() const; - const std::string& getFaviconMimeType() const; + DEPRECATED const std::string& getFavicon() const; + DEPRECATED const std::string& getFaviconUrl() const; + DEPRECATED const std::string& getFaviconMimeType() const; Illustrations getIllustrations() const; std::shared_ptr getIllustration(unsigned int size) const; diff --git a/src/libxml_dumper.cpp b/src/libxml_dumper.cpp index db03a2005..6dc884d24 100644 --- a/src/libxml_dumper.cpp +++ b/src/libxml_dumper.cpp @@ -60,10 +60,13 @@ void LibXMLDumper::handleBook(Book book, pugi::xml_node root_node) { ADD_ATTR_NOT_EMPTY(entry_node, "name", book.getName()); ADD_ATTR_NOT_EMPTY(entry_node, "flavour", book.getFlavour()); ADD_ATTR_NOT_EMPTY(entry_node, "tags", book.getTags()); - ADD_ATTR_NOT_EMPTY(entry_node, "faviconMimeType", book.getFaviconMimeType()); - ADD_ATTR_NOT_EMPTY(entry_node, "faviconUrl", book.getFaviconUrl()); - if (!book.getFavicon().empty()) - ADD_ATTRIBUTE(entry_node, "favicon", base64_encode(book.getFavicon())); + try { + auto defaultIllustration = book.getIllustration(48); + ADD_ATTR_NOT_EMPTY(entry_node, "faviconMimeType", defaultIllustration->mimeType); + ADD_ATTR_NOT_EMPTY(entry_node, "faviconUrl", defaultIllustration->url); + if (!defaultIllustration->getData().empty()) + ADD_ATTRIBUTE(entry_node, "favicon", base64_encode(defaultIllustration->getData())); + } catch(...) {} } else { ADD_ATTRIBUTE(entry_node, "origId", book.getOrigId()); } diff --git a/test/book.cpp b/test/book.cpp index 2de31cfe5..4ed2df77a 100644 --- a/test/book.cpp +++ b/test/book.cpp @@ -52,9 +52,10 @@ TEST(BookTest, updateFromXMLTest) EXPECT_EQ(book.getArticleCount(), 123456U); EXPECT_EQ(book.getMediaCount(), 234567U); EXPECT_EQ(book.getSize(), 345678U*1024U); - EXPECT_EQ(book.getFavicon(), "fake-book-favicon-data"); - EXPECT_EQ(book.getFaviconMimeType(), "text/plain"); - EXPECT_EQ(book.getFaviconUrl(), "http://who.org/zara.fav"); + auto defaultIllustration = book.getIllustration(48); + EXPECT_EQ(defaultIllustration->getData(), "fake-book-favicon-data"); + EXPECT_EQ(defaultIllustration->mimeType, "text/plain"); + EXPECT_EQ(defaultIllustration->url, "http://who.org/zara.fav"); } TEST(BookTest, updateFromXMLCategoryHandlingTest) @@ -175,8 +176,10 @@ TEST(BookTest, updateTest) EXPECT_EQ(newBook.getTags(), book.getTags()); EXPECT_EQ(newBook.getCategory(), book.getCategory()); EXPECT_EQ(newBook.getName(), book.getName()); - EXPECT_EQ(newBook.getFavicon(), book.getFavicon()); - EXPECT_EQ(newBook.getFaviconMimeType(), book.getFaviconMimeType()); + auto defaultIllustration = book.getIllustration(48); + auto newDefaultIllustration = newBook.getIllustration(48); + EXPECT_EQ(newDefaultIllustration->getData(), defaultIllustration->getData()); + EXPECT_EQ(newDefaultIllustration->mimeType, defaultIllustration->mimeType); } namespace From 96e0d15ab453f0b27e3790df13d0fcfb959b582b Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:10:28 +0100 Subject: [PATCH 2/7] Deprecate `Entry` creation. As the `Entry` is still created by `Reader` we need a way to create a entry without raising a deprecated warning. To do so we create a second constructor with a dummy argument. This second constructor is private and is not marked as deprecated so we can use it. --- include/entry.h | 12 +++++++++++- src/entry.cpp | 6 +++--- src/reader.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/entry.h b/include/entry.h index bbddebd0e..a5b1b4746 100644 --- a/include/entry.h +++ b/include/entry.h @@ -47,7 +47,7 @@ class Entry * * @param article a zim::Article object */ - Entry(zim::Entry entry); + DEPRECATED Entry(zim::Entry entry) : Entry(entry, true) {}; virtual ~Entry() = default; /** @@ -176,6 +176,16 @@ class Entry private: zim::Entry entry; + + private: + // Entry is deprecated, so we've marked the constructor as deprecated. + // But we still need to construct the entry (in our deprecated code) + // To avoid warning because we use deprecated function, we create a second + // constructor not deprecated. The `bool marker` is unused, it sole purpose + // is to change the signature to have two different constructor. + // This one is not deprecated and we must use it in our private code. + Entry(zim::Entry entry, bool marker); + friend class Reader; }; } diff --git a/src/entry.cpp b/src/entry.cpp index 91abbe6e9..02f8640c4 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -23,7 +23,7 @@ namespace kiwix { -Entry::Entry(zim::Entry entry) +Entry::Entry(zim::Entry entry, bool _marker) : entry(entry) { } @@ -53,7 +53,7 @@ Entry Entry::getRedirectEntry() const throw NoEntry(); } - return entry.getRedirectEntry(); + return Entry(entry.getRedirectEntry(), true); } Entry Entry::getFinalEntry() const @@ -67,7 +67,7 @@ Entry Entry::getFinalEntry() const if (final_entry.isRedirect()) { throw NoEntry(); } - return final_entry; + return Entry(final_entry, true); } } diff --git a/src/reader.cpp b/src/reader.cpp index 6af7de6f7..7bcbe8707 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -122,7 +122,7 @@ string Reader::getId() const Entry Reader::getRandomPage() const { try { - return zimArchive->getRandomEntry(); + return Entry(zimArchive->getRandomEntry(), true); } catch(...) { throw NoEntry(); } @@ -130,7 +130,7 @@ Entry Reader::getRandomPage() const Entry Reader::getMainPage() const { - return zimArchive->getMainEntry(); + return Entry(zimArchive->getMainEntry(), true); } bool Reader::getFavicon(string& content, string& mimeType) const @@ -242,7 +242,7 @@ string Reader::getScraper() const Entry Reader::getEntryFromPath(const std::string& path) const { try { - return kiwix::getEntryFromPath(*zimArchive, path); + return Entry(kiwix::getEntryFromPath(*zimArchive, path), true); } catch (zim::EntryNotFound& e) { throw NoEntry(); } @@ -256,7 +256,7 @@ Entry Reader::getEntryFromEncodedPath(const std::string& path) const Entry Reader::getEntryFromTitle(const std::string& title) const { try { - return zimArchive->getEntryByTitle(title); + return Entry(zimArchive->getEntryByTitle(title), true); } catch(zim::EntryNotFound& e) { throw NoEntry(); } From fb7d9f02c83bfe12e2103357c8656c04a9bed9ba Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:12:59 +0100 Subject: [PATCH 3/7] Deprecate `Reader` creation. As we `Reader` is now deprecated, we also remove the unit tests on it. `Reader` is now untested, and so it reduces the code coverage. --- include/library.h | 2 +- include/reader.h | 10 +++++--- test/library.cpp | 4 +-- test/meson.build | 1 - test/reader.cpp | 62 ----------------------------------------------- 5 files changed, 9 insertions(+), 70 deletions(-) delete mode 100644 test/reader.cpp diff --git a/include/library.h b/include/library.h index d54c8db4a..823cb295e 100644 --- a/include/library.h +++ b/include/library.h @@ -240,7 +240,7 @@ class Library : private LibraryBase Book getBookByIdThreadSafe(const std::string& id) const; - std::shared_ptr getReaderById(const std::string& id); + DEPRECATED std::shared_ptr getReaderById(const std::string& id); std::shared_ptr getArchiveById(const std::string& id); /** diff --git a/include/reader.h b/include/reader.h index 24d8d02fc..b23daf254 100644 --- a/include/reader.h +++ b/include/reader.h @@ -73,6 +73,8 @@ class SuggestionItem /** * The Reader class is the class who allow to get an entry content from a zim * file. + * + * Reader is now deprecated. Directly use `zim::Archive`. */ using SuggestionsList_t = std::vector; @@ -88,17 +90,17 @@ class Reader * unsplitted path as if the file were not splitted * (.zim extesion). */ - explicit Reader(const string zimFilePath); + explicit DEPRECATED Reader(const string zimFilePath); /** * Create a Reader to read a zim file given by the Archive. * * @param archive The shared pointer to the Archive object. */ - explicit Reader(const std::shared_ptr archive); + explicit DEPRECATED Reader(const std::shared_ptr archive); #ifndef _WIN32 - explicit Reader(int fd); - Reader(int fd, zim::offset_type offset, zim::size_type size); + explicit DEPRECATED Reader(int fd); + DEPRECATED Reader(int fd, zim::offset_type offset, zim::size_type size); #endif ~Reader() = default; diff --git a/test/library.cpp b/test/library.cpp index a8d99e896..1f0079b49 100644 --- a/test/library.cpp +++ b/test/library.cpp @@ -684,9 +684,9 @@ TEST_F(LibraryTest, removeBookByIdRemovesTheBook) TEST_F(LibraryTest, removeBookByIdDropsTheReader) { - EXPECT_NE(nullptr, lib.getReaderById("raycharles")); + EXPECT_NE(nullptr, lib.getArchiveById("raycharles")); lib.removeBookById("raycharles"); - EXPECT_THROW(lib.getReaderById("raycharles"), std::out_of_range); + EXPECT_THROW(lib.getArchiveById("raycharles"), std::out_of_range); }; TEST_F(LibraryTest, removeBookByIdUpdatesTheSearchDB) diff --git a/test/meson.build b/test/meson.build index 939f99b7c..43d7a1e78 100644 --- a/test/meson.build +++ b/test/meson.build @@ -10,7 +10,6 @@ tests = [ 'manager', 'name_mapper', 'opds_catalog', - 'reader', 'searcher' ] diff --git a/test/reader.cpp b/test/reader.cpp deleted file mode 100644 index 2c25207dc..000000000 --- a/test/reader.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -#include "gtest/gtest.h" -#include "../include/reader.h" -#include "zim/archive.h" - -namespace kiwix -{ - /** - * This test file is written primarily to demonstrate how Reader is simply a - * wrapper over an archive. We will be dropping this wrapper soon. - **/ - TEST (Reader, archiveWrapper) { - Reader reader("./test/zimfile.zim"); - zim::Archive archive = *reader.getZimArchive(); - - std::ostringstream s; - s << archive.getUuid(); - - ASSERT_EQ(reader.getId(), s.str()); - ASSERT_EQ(reader.getGlobalCount(), archive.getEntryCount()); - ASSERT_EQ(reader.getMainPage().getTitle(), archive.getMainEntry().getTitle()); - ASSERT_EQ(reader.hasFulltextIndex(), archive.hasFulltextIndex()); - ASSERT_NO_THROW(reader.getRandomPage()); - } - - TEST (Reader, getFunctions) { - zim::Archive archive("./test/zimfile.zim"); - Reader reader("./test/zimfile.zim"); - - auto archiveEntry = archive.getRandomEntry(); - ASSERT_TRUE(reader.pathExists(archiveEntry.getPath())); - auto readerEntry = reader.getEntryFromPath(archiveEntry.getPath()); - ASSERT_EQ(readerEntry.getTitle(), archiveEntry.getTitle()); - - ASSERT_FALSE(reader.pathExists("invalidEntryPath")); - ASSERT_THROW(reader.getEntryFromPath("invalidEntryPath"), NoEntry); - - readerEntry = reader.getEntryFromTitle(archiveEntry.getTitle()); - ASSERT_EQ(readerEntry.getTitle(), archiveEntry.getTitle()); - } - - TEST (Reader, suggestions) { - Reader reader("./test/zimfile.zim"); - SuggestionsList_t suggestions; - reader.searchSuggestionsSmart("The Genius", 4, suggestions); - - std::vector suggestionResult, expectedResult; - std::string suggestionTitle; - for (auto it = suggestions.begin(); it != suggestions.end(); it++) { - suggestionResult.push_back(it->getTitle()); - } - - expectedResult = { - "The Genius After Hours", - "The Genius Hits the Road", - "The Genius Sings the Blues", - "The Genius of Ray Charles" - }; - - ASSERT_EQ(suggestionResult, expectedResult); - } -} \ No newline at end of file From 3d64a9d9a978da44e7083628cbf9c411ce5cba72 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:13:51 +0100 Subject: [PATCH 4/7] Deprecate `Searcher` creation. As the `Searcher` is now deprecated, we also remove the unit tests on it. `Searcher` is now untested, and so it reduces the code coverage. --- include/searcher.h | 4 ++- test/meson.build | 3 +- test/searcher.cpp | 79 ---------------------------------------------- 3 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 test/searcher.cpp diff --git a/include/searcher.h b/include/searcher.h index e677cc98e..4381c1d30 100644 --- a/include/searcher.h +++ b/include/searcher.h @@ -56,6 +56,8 @@ struct SuggestionInternal; /** * The Searcher class is reponsible to do different kind of search using the * fulltext index. + * + * The Searcher is now deprecated. Use libzim search feature. */ class Searcher { @@ -63,7 +65,7 @@ class Searcher /** * The default constructor. */ - Searcher(); + DEPRECATED Searcher(); ~Searcher(); diff --git a/test/meson.build b/test/meson.build index 43d7a1e78..62b210871 100644 --- a/test/meson.build +++ b/test/meson.build @@ -9,8 +9,7 @@ tests = [ 'book', 'manager', 'name_mapper', - 'opds_catalog', - 'searcher' + 'opds_catalog' ] if build_machine.system() != 'windows' diff --git a/test/searcher.cpp b/test/searcher.cpp deleted file mode 100644 index 5adb0adeb..000000000 --- a/test/searcher.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "gtest/gtest.h" -#include "../include/searcher.h" -#include "../include/reader.h" - -namespace kiwix -{ - -TEST(Searcher, add_reader) { - Reader reader1("./test/example.zim"); - Reader reader2("./test/example.zim"); - Reader reader3("./test/../test/example.zim"); - - Searcher searcher; - ASSERT_TRUE (searcher.add_reader(&reader1)); - ASSERT_FALSE(searcher.add_reader(&reader1)); - ASSERT_FALSE(searcher.add_reader(&reader2)); - ASSERT_FALSE(searcher.add_reader(&reader3)); -} - -TEST(Searcher, search) { - Reader reader("./test/example.zim"); - - Searcher searcher; - searcher.add_reader(&reader); - ASSERT_EQ(searcher.get_reader(0)->getTitle(), reader.getTitle()); - - searcher.search("wiki", 0, 2); - searcher.restart_search(); - ASSERT_EQ(searcher.getEstimatedResultCount(), (unsigned int)2); - - auto result = searcher.getNextResult(); - ASSERT_EQ(result->get_title(), "FreedomBox for Communities/Offline Wikipedia - Wikibooks, open books for an open world"); - result = searcher.getNextResult(); - ASSERT_EQ(result->get_title(), "Wikibooks"); -} - -TEST(Searcher, suggestion) { - Reader reader("./test/zimfile.zim"); - - Searcher searcher; - searcher.add_reader(&reader); - ASSERT_EQ(searcher.get_reader(0)->getTitle(), reader.getTitle()); - - std::string query = "ray"; - searcher.suggestions(query, true); - searcher.restart_search(); - - auto result = searcher.getNextResult(); - ASSERT_EQ(result->get_title(), "Charles, Ray"); - ASSERT_EQ(result->get_url(), "A/Charles,_Ray"); - ASSERT_EQ(result->get_snippet(), "Charles, Ray"); - ASSERT_EQ(result->get_score(), 0); - ASSERT_EQ(result->get_content(), ""); - ASSERT_EQ(result->get_size(), 0); - ASSERT_EQ(result->get_wordCount(), 0); - ASSERT_EQ(result->get_zimId(), ""); - - result = searcher.getNextResult(); - ASSERT_EQ(result->get_title(), "Ray (film)"); -} - -TEST(Searcher, incrementalRange) { - // Attempt to get 50 results in steps of 5 - zim::Archive archive("./test/zimfile.zim"); - zim::Searcher ftsearcher(archive); - zim::Query query; - query.setQuery("ray"); - auto search = ftsearcher.search(query); - - int suggCount = 0; - for (int i = 0; i < 10; i++) { - auto srs = search.getResults(i*5, 5); // get 5 results - ASSERT_EQ(srs.size(), 5); - suggCount += srs.size(); - } - ASSERT_EQ(suggCount, 50); -} - -} From e5d26a4699054b6eb29e8a41d5ef1c9306d05f9b Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:14:39 +0100 Subject: [PATCH 5/7] Deprecate `SearchRenderer` creation from a `Searcher`. --- include/search_renderer.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/search_renderer.h b/include/search_renderer.h index 5951ff8a7..5713ca2fe 100644 --- a/include/search_renderer.h +++ b/include/search_renderer.h @@ -35,12 +35,24 @@ class SearchRenderer { public: /** - * The default constructor. + * Construct a SearchRenderer from a Searcher. * - * @param humanReadableName The global zim's humanReadableName. - * Used to generate pagination links. + * This method is now deprecated. Construct the renderer from a + * `zim::SearchResultSet` + * + * @param searcher The `Searcher` to render. + * @param mapper The `NameMapper` to use to do the rendering. + */ + DEPRECATED SearchRenderer(Searcher* searcher, NameMapper* mapper); + + /** + * Construct a SearchRenderer from a SearchResultSet. + * + * @param srs The `SearchResultSet` to render. + * @param mapper The `NameMapper` to use to do the rendering. + * @param start The start offset used for the srs. + * @param estimatedResultCount The estimatedResultCount of the whole search */ - SearchRenderer(Searcher* searcher, NameMapper* mapper); SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, unsigned int start, unsigned int estimatedResultCount); From ac6f91798f10d25d735535c0a0d3e9a85b8bb33e Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:16:07 +0100 Subject: [PATCH 6/7] Assume `SuggestionItem` has a public constructor. `SuggestionItem` is somehow a simple container. --- include/reader.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/reader.h b/include/reader.h index b23daf254..12d06a114 100644 --- a/include/reader.h +++ b/include/reader.h @@ -42,7 +42,6 @@ namespace kiwix class SuggestionItem { // Functions - // Temporarily making the constructor public until the code move is complete public: // Create a sugggestion item. explicit SuggestionItem(const std::string& title, const std::string& normalizedTitle, @@ -66,8 +65,6 @@ class SuggestionItem std::string normalizedTitle; std::string path; std::string snippet; - - friend class Reader; }; /** From e5eeb08206f231531e7686f4f2e5fcb32e26ecdf Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 12 Jan 2022 18:46:11 +0100 Subject: [PATCH 7/7] Remove old deprecated methods. --- include/library.h | 43 ---------------------------- include/reader.h | 63 ----------------------------------------- src/library.cpp | 51 ---------------------------------- src/reader.cpp | 71 ----------------------------------------------- 4 files changed, 228 deletions(-) diff --git a/include/library.h b/include/library.h index 823cb295e..dc4463f62 100644 --- a/include/library.h +++ b/include/library.h @@ -325,17 +325,6 @@ class Library : private LibraryBase */ BookIdCollection getBooksIds() const; - /** - * Filter the library and generate a new one with the keep elements. - * - * This is equivalent to `listBookIds(ALL, UNSORTED, search)`. - * - * @param search List only books with search in the title or description. - * @return The list of bookIds corresponding to the query. - */ - DEPRECATED BookIdCollection filter(const std::string& search) const; - - /** * Filter the library and return the id of the keep elements. * @@ -354,38 +343,6 @@ class Library : private LibraryBase */ void sort(BookIdCollection& bookIds, supportedListSortBy sortBy, bool ascending) const; - /** - * List books in the library. - * - * @param mode The mode of listing : - * - LOCALĀ  : list only local books (with a path). - * - REMOTE : list only remote books (with an url). - * - VALIDĀ  : list only valid books (without a path or with a - * path pointing to a valid zim file). - * - NOLOCAL : list only books without valid path. - * - NOREMOTE : list only books without url. - * - NOVALID : list only books not valid. - * - ALL : Do not do any filter (LOCAL or REMOTE) - * - Flags can be combined. - * @param sortBy Attribute to sort by the book list. - * @param search List only books with search in the title, description. - * @param language List only books in this language. - * @param creator List only books of this creator. - * @param publisher List only books of this publisher. - * @param maxSize Do not list book bigger than maxSize. - * Set to 0 to cancel this filter. - * @return The list of bookIds corresponding to the query. - */ - DEPRECATED BookIdCollection listBooksIds( - int supportedListMode = ALL, - supportedListSortBy sortBy = UNSORTED, - const std::string& search = "", - const std::string& language = "", - const std::string& creator = "", - const std::string& publisher = "", - const std::vector& tags = {}, - size_t maxSize = 0) const; - /** * Return the current revision of the library. * diff --git a/include/reader.h b/include/reader.h index 12d06a114..ee5e2531a 100644 --- a/include/reader.h +++ b/include/reader.h @@ -329,28 +329,6 @@ class Reader */ Entry getEntryFromTitle(const std::string& title) const; - /** - * Search for entries with title starting with prefix (case sensitive). - * - * Suggestions are stored in an internal vector and can be retrieved using - * `getNextSuggestion` method. - * This method is not thread safe and is deprecated. Use : - * bool searchSuggestions(const string& prefix, - * unsigned int suggestionsCount, - * SuggestionsList_t& results); - * - * @param prefix The prefix to search. - * @param suggestionsCount How many suggestions to search for. - * @param reset If true, remove previous suggestions in the internal vector. - * If false, add suggestions to the internal vector - * (until internal vector size is suggestionCount (or no more - * suggestion)) - * @return True if some suggestions have been added to the internal vector. - */ - DEPRECATED bool searchSuggestions(const string& prefix, - unsigned int suggestionsCount, - const bool reset = true); - /** * Search for entries with title starting with prefix (case sensitive). * @@ -366,28 +344,6 @@ class Reader unsigned int suggestionsCount, SuggestionsList_t& resuls); - /** - * Search for entries for the given prefix. - * - * If the zim file has a internal fulltext index, the suggestions will be - * searched using it. - * Else the suggestions will be search using `searchSuggestions` while trying - * to be smart about case sensitivity (using `getTitleVariants`). - * - * In any case, suggestions are stored in an internal vector and can be - * retrieved using `getNextSuggestion` method. - * The internal vector will be reset. - * This method is not thread safe and is deprecated. Use : - * bool searchSuggestionsSmart(const string& prefix, - * unsigned int suggestionsCount, - * SuggestionsList_t& results); - * - * @param prefix The prefix to search for. - * @param suggestionsCount How many suggestions to search for. - */ - DEPRECATED bool searchSuggestionsSmart(const string& prefix, - unsigned int suggestionsCount); - /** * Search for entries for the given prefix. * @@ -434,22 +390,6 @@ class Reader */ std::vector getTitleVariants(const std::string& title) const; - /** - * Get the next suggestion title. - * - * @param[out] title the title of the suggestion. - * @return True if title has been set. - */ - DEPRECATED bool getNextSuggestion(string& title); - - /** - * Get the next suggestion title and url. - * - * @param[out] title the title of the suggestion. - * @param[out] url the url of the suggestion. - * @return True if title and url have been set. - */ - DEPRECATED bool getNextSuggestion(string& title, string& url); /** * Get if we can check zim file integrity (has a checksum). @@ -485,9 +425,6 @@ class Reader std::shared_ptr zimArchive; std::string zimFilePath; - SuggestionsList_t suggestions; - SuggestionsList_t::iterator suggestionsOffset; - private: std::map parseCounterMetadata() const; }; diff --git a/src/library.cpp b/src/library.cpp index 760e3d142..47768a513 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -366,15 +366,6 @@ Library::BookIdCollection Library::getBooksIds() const return bookIds; } -Library::BookIdCollection Library::filter(const std::string& search) const -{ - if (search.empty()) { - return getBooksIds(); - } - - return filter(Filter().query(search)); -} - void Library::updateBookDB(const Book& book) { @@ -658,48 +649,6 @@ void Library::sort(BookIdCollection& bookIds, supportedListSortBy sort, bool asc } -Library::BookIdCollection Library::listBooksIds( - int mode, - supportedListSortBy sortBy, - const std::string& search, - const std::string& language, - const std::string& creator, - const std::string& publisher, - const std::vector& tags, - size_t maxSize) const { - - Filter _filter; - if (mode & LOCAL) - _filter.local(true); - if (mode & NOLOCAL) - _filter.local(false); - if (mode & VALID) - _filter.valid(true); - if (mode & NOVALID) - _filter.valid(false); - if (mode & REMOTE) - _filter.remote(true); - if (mode & NOREMOTE) - _filter.remote(false); - if (!tags.empty()) - _filter.acceptTags(tags); - if (maxSize != 0) - _filter.maxSize(maxSize); - if (!language.empty()) - _filter.lang(language); - if (!publisher.empty()) - _filter.publisher(publisher); - if (!creator.empty()) - _filter.creator(creator); - if (!search.empty()) - _filter.query(search); - - auto bookIds = filter(_filter); - - sort(bookIds, sortBy, true); - return bookIds; -} - Filter::Filter() : activeFilters(0), _maxSize(0) diff --git a/src/reader.cpp b/src/reader.cpp index 7bcbe8707..24b0a7ecb 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -273,32 +273,6 @@ bool Reader::hasFulltextIndex() const return zimArchive->hasFulltextIndex(); } -/* Search titles by prefix */ - -bool Reader::searchSuggestions(const string& prefix, - unsigned int suggestionsCount, - const bool reset) -{ - /* Reset the suggestions otherwise check if the suggestions number is less - * than the suggestionsCount */ - if (reset) { - this->suggestions.clear(); - this->suggestionsOffset = this->suggestions.begin(); - } else { - if (this->suggestions.size() > suggestionsCount) { - return false; - } - } - - auto ret = searchSuggestions(prefix, suggestionsCount, this->suggestions); - - /* Set the cursor to the begining */ - this->suggestionsOffset = this->suggestions.begin(); - - return ret; -} - - bool Reader::searchSuggestions(const string& prefix, unsigned int suggestionsCount, SuggestionsList_t& results) @@ -359,19 +333,6 @@ std::vector Reader::getTitleVariants( } -bool Reader::searchSuggestionsSmart(const string& prefix, - unsigned int suggestionsCount) -{ - this->suggestions.clear(); - this->suggestionsOffset = this->suggestions.begin(); - - auto ret = searchSuggestionsSmart(prefix, suggestionsCount, this->suggestions); - - this->suggestionsOffset = this->suggestions.begin(); - - return ret; -} - /* Try also a few variations of the prefix to have better results */ bool Reader::searchSuggestionsSmart(const string& prefix, unsigned int suggestionsCount, @@ -410,38 +371,6 @@ bool Reader::searchSuggestionsSmart(const string& prefix, return results.size() > 0; } -/* Get next suggestion */ -bool Reader::getNextSuggestion(string& title) -{ - if (this->suggestionsOffset != this->suggestions.end()) { - /* title */ - title = (*(this->suggestionsOffset)).getTitle(); - - /* increment the cursor for the next call */ - this->suggestionsOffset++; - - return true; - } - - return false; -} - -bool Reader::getNextSuggestion(string& title, string& url) -{ - if (this->suggestionsOffset != this->suggestions.end()) { - /* title */ - title = (*(this->suggestionsOffset)).getTitle(); - url = (*(this->suggestionsOffset)).getPath(); - - /* increment the cursor for the next call */ - this->suggestionsOffset++; - - return true; - } - - return false; -} - /* Check if the file has as checksum */ bool Reader::canCheckIntegrity() const {