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