mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #470 from kiwix/xapian_should_not_be_exposed
This commit is contained in:
commit
e4be97a032
|
@ -28,7 +28,6 @@
|
|||
#include "book.h"
|
||||
#include "bookmark.h"
|
||||
#include "common.h"
|
||||
#include <xapian.h>
|
||||
|
||||
#define KIWIX_LIBRARY_VERSION "20110515"
|
||||
|
||||
|
@ -125,7 +124,8 @@ class Library
|
|||
std::map<std::string, kiwix::Book> m_books;
|
||||
std::map<std::string, std::shared_ptr<Reader>> m_readers;
|
||||
std::vector<kiwix::Bookmark> m_bookmarks;
|
||||
Xapian::WritableDatabase m_bookDB;
|
||||
class BookDB;
|
||||
std::unique_ptr<BookDB> m_bookDB;
|
||||
|
||||
public:
|
||||
typedef std::vector<std::string> BookIdCollection;
|
||||
|
@ -134,6 +134,14 @@ class Library
|
|||
Library();
|
||||
~Library();
|
||||
|
||||
/**
|
||||
* Library is not a copiable object. However it can be moved.
|
||||
*/
|
||||
Library(const Library& ) = delete;
|
||||
Library(Library&& );
|
||||
void operator=(const Library& ) = delete;
|
||||
Library& operator=(Library&& );
|
||||
|
||||
/**
|
||||
* Add a book to the library.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <unicode/locid.h>
|
||||
#include <xapian.h>
|
||||
|
||||
namespace kiwix
|
||||
{
|
||||
|
@ -49,12 +50,22 @@ std::string normalizeText(const std::string& text, const std::string& language)
|
|||
|
||||
} // unnamed namespace
|
||||
|
||||
class Library::BookDB : public Xapian::WritableDatabase
|
||||
{
|
||||
public:
|
||||
BookDB() : Xapian::WritableDatabase("", Xapian::DB_BACKEND_INMEMORY) {}
|
||||
};
|
||||
|
||||
/* Constructor */
|
||||
Library::Library()
|
||||
: m_bookDB("", Xapian::DB_BACKEND_INMEMORY)
|
||||
: m_bookDB(new BookDB)
|
||||
{
|
||||
}
|
||||
|
||||
Library::Library(Library&& ) = default;
|
||||
|
||||
Library& Library::operator=(Library&& ) = default;
|
||||
|
||||
/* Destructor */
|
||||
Library::~Library()
|
||||
{
|
||||
|
@ -279,7 +290,7 @@ void Library::updateBookDB(const Book& book)
|
|||
|
||||
const std::string idterm = "Q" + book.getId();
|
||||
doc.add_boolean_term(idterm);
|
||||
m_bookDB.replace_document(idterm, doc);
|
||||
m_bookDB->replace_document(idterm, doc);
|
||||
}
|
||||
|
||||
Library::BookIdCollection Library::getBooksByTitleOrDescription(const Filter& filter)
|
||||
|
@ -305,7 +316,7 @@ Library::BookIdCollection Library::getBooksByTitleOrDescription(const Filter& fi
|
|||
| Xapian::QueryParser::FLAG_WILDCARD
|
||||
| partialQueryFlag;
|
||||
const auto query = queryParser.parse_query(filter.getQuery(), flags);
|
||||
Xapian::Enquire enquire(m_bookDB);
|
||||
Xapian::Enquire enquire(*m_bookDB);
|
||||
enquire.set_query(query);
|
||||
const auto results = enquire.get_mset(0, m_books.size());
|
||||
for ( auto it = results.begin(); it != results.end(); ++it ) {
|
||||
|
|
Loading…
Reference in New Issue