11#include "akonadi_search_pim_debug.h"
13#include "resultiterator_p.h"
18#include <QStandardPaths>
22class Akonadi::Search::PIM::NoteQueryPrivate
25 NoteQueryPrivate() =
default;
34 , d(new NoteQueryPrivate)
38NoteQuery::~NoteQuery() =
default;
40void NoteQuery::matchTitle(
const QString &title)
45void NoteQuery::matchNote(
const QString ¬e)
50void NoteQuery::setLimit(
int limit)
55int NoteQuery::limit()
const
62 const QString
dir = defaultLocation(QStringLiteral(
"notes"));
67 }
catch (
const Xapian::DatabaseOpeningError &) {
68 qCWarning(AKONADI_SEARCH_PIM_LOG) <<
"Xapian Database does not exist at " <<
dir;
70 }
catch (
const Xapian::DatabaseCorruptError &) {
71 qCWarning(AKONADI_SEARCH_PIM_LOG) <<
"Xapian Database corrupted";
73 }
catch (
const Xapian::DatabaseError &e) {
74 qCWarning(AKONADI_SEARCH_PIM_LOG) <<
"Failed to open Xapian database:" <<
QString::fromStdString(e.get_error_string());
77 qCWarning(AKONADI_SEARCH_PIM_LOG) <<
"Random exception, but we do not want to crash";
81 QList<Xapian::Query> m_queries;
83 if (!d->note.isEmpty()) {
84 Xapian::QueryParser parser;
85 parser.set_database(db);
86 parser.add_prefix(
"",
"BO");
88 const QByteArray baNote = d->note.toUtf8();
89 m_queries << parser.parse_query(baNote.
constData(), Xapian::QueryParser::FLAG_PARTIAL);
92 if (!d->title.isEmpty()) {
93 Xapian::QueryParser parser;
94 parser.set_database(db);
95 parser.add_prefix(
"",
"SU");
96 parser.set_default_op(Xapian::Query::OP_AND);
98 const QByteArray baTitle = d->title.toUtf8();
99 m_queries << parser.parse_query(baTitle.
constData(), Xapian::QueryParser::FLAG_PARTIAL);
102 Xapian::Query
query(Xapian::Query::OP_OR, m_queries.
begin(), m_queries.
end());
105 Xapian::Enquire enquire(db);
106 enquire.set_query(query);
112 Xapian::MSet matches = enquire.get_mset(0, d->limit);
115 iter.d->init(matches);
117 }
catch (
const Xapian::Error &e) {
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
KIOCORE_EXPORT QString dir(const QString &fileClass)
const char * constData() const const
QByteArray encodeName(const QString &fileName)
QString fromStdString(const std::string &str)