Skip to content

Commit

Permalink
Xapian headers are not exposed through libkiwix
Browse files Browse the repository at this point in the history
  • Loading branch information
veloman-yunkan committed Mar 21, 2021
1 parent baed447 commit 516f0c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion include/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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;
Expand All @@ -134,6 +135,9 @@ class Library
Library();
~Library();

Library(const Library& ) = delete;
void operator=(const Library& ) = delete;

/**
* Add a book to the library.
*
Expand Down
13 changes: 10 additions & 3 deletions src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <algorithm>
#include <set>
#include <unicode/locid.h>
#include <xapian.h>

namespace kiwix
{
Expand All @@ -49,9 +50,15 @@ 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)
{
}

Expand Down Expand Up @@ -279,7 +286,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)
Expand All @@ -305,7 +312,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 ) {
Expand Down

0 comments on commit 516f0c1

Please sign in to comment.