mirror of https://github.com/djcb/mu.git
query-results: Use mu-document as backend
So the mu-specific serialization/deserialization gets handled correctly
This commit is contained in:
parent
a864616110
commit
91d2a37379
|
@ -59,7 +59,6 @@ public:
|
||||||
Document(const Document& rhs) { *this = rhs; }
|
Document(const Document& rhs) { *this = rhs; }
|
||||||
/**
|
/**
|
||||||
* Move CTOR
|
* Move CTOR
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
Document(Document&& rhs) {*this = std::move(rhs); }
|
Document(Document&& rhs) {*this = std::move(rhs); }
|
||||||
|
|
||||||
|
@ -94,6 +93,13 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the doc-id for this document
|
||||||
|
*
|
||||||
|
* @return the docid
|
||||||
|
*/
|
||||||
|
Xapian::docid docid() const { return xdoc_.get_docid(); }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* updating a document with terms & values
|
* updating a document with terms & values
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -167,8 +167,7 @@ public:
|
||||||
using reference = void;
|
using reference = void;
|
||||||
|
|
||||||
QueryResultsIterator(Xapian::MSetIterator mset_it, QueryMatches& query_matches)
|
QueryResultsIterator(Xapian::MSetIterator mset_it, QueryMatches& query_matches)
|
||||||
: mset_it_{mset_it}, query_matches_{query_matches}
|
: mset_it_{mset_it}, query_matches_{query_matches} {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,9 +175,9 @@ public:
|
||||||
*
|
*
|
||||||
* @return an updated iterator, or end() if we were already at end()
|
* @return an updated iterator, or end() if we were already at end()
|
||||||
*/
|
*/
|
||||||
QueryResultsIterator& operator++()
|
QueryResultsIterator& operator++() {
|
||||||
{
|
|
||||||
++mset_it_;
|
++mset_it_;
|
||||||
|
document_.reset();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,12 +195,17 @@ public:
|
||||||
const QueryResultsIterator& operator*() const { return *this; }
|
const QueryResultsIterator& operator*() const { return *this; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Xapian document this iterator is pointing at,
|
* Get the Mu::Document this iterator is pointing at,
|
||||||
* or an empty document when looking at end().
|
* or an empty document when looking at end().
|
||||||
*
|
*
|
||||||
* @return a document
|
* @return a document
|
||||||
*/
|
*/
|
||||||
Xapian::Document document() const { return mset_it_.get_document(); }
|
const Mu::Document& document() const {
|
||||||
|
if (!document_)
|
||||||
|
document_.emplace(mset_it_.get_document());
|
||||||
|
return *document_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the doc-id for the document this iterator is pointing at, or 0
|
* Get the doc-id for the document this iterator is pointing at, or 0
|
||||||
|
@ -264,9 +268,8 @@ public:
|
||||||
*
|
*
|
||||||
* @return references
|
* @return references
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> references() const noexcept
|
std::vector<std::string> references() const noexcept {
|
||||||
{
|
return document().string_vec_value(Field::Id::References);
|
||||||
return split(opt_string(Field::Id::References).value_or(""), ",");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,12 +279,8 @@ public:
|
||||||
*
|
*
|
||||||
* @return the value
|
* @return the value
|
||||||
*/
|
*/
|
||||||
Option<std::string> opt_string(Field::Id id) const noexcept
|
Option<std::string> opt_string(Field::Id id) const noexcept {
|
||||||
{
|
if (auto&& val{document().string_value(id)}; val.empty())
|
||||||
std::string empty;
|
|
||||||
const auto value_no{field_from_id(id).value_no()};
|
|
||||||
std::string val = xapian_try([&] {return document().get_value(value_no);}, empty);
|
|
||||||
if (val.empty())
|
|
||||||
return Nothing;
|
return Nothing;
|
||||||
else
|
else
|
||||||
return Some(std::move(val));
|
return Some(std::move(val));
|
||||||
|
@ -292,15 +291,13 @@ public:
|
||||||
*
|
*
|
||||||
* @return the match info.
|
* @return the match info.
|
||||||
*/
|
*/
|
||||||
QueryMatch& query_match()
|
QueryMatch& query_match() {
|
||||||
{
|
g_assert(query_matches_.find(document().docid()) != query_matches_.end());
|
||||||
g_assert(query_matches_.find(document().get_docid()) != query_matches_.end());
|
return query_matches_.find(document().docid())->second;
|
||||||
return query_matches_.find(document().get_docid())->second;
|
|
||||||
}
|
}
|
||||||
const QueryMatch& query_match() const
|
const QueryMatch& query_match() const {
|
||||||
{
|
g_assert(query_matches_.find(document().docid()) != query_matches_.end());
|
||||||
g_assert(query_matches_.find(document().get_docid()) != query_matches_.end());
|
return query_matches_.find(document().docid())->second;
|
||||||
return query_matches_.find(document().get_docid())->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -311,7 +308,8 @@ public:
|
||||||
Option<Message> message() const {
|
Option<Message> message() const {
|
||||||
return xapian_try(
|
return xapian_try(
|
||||||
[&]()->Option<Message> {
|
[&]()->Option<Message> {
|
||||||
if (auto&& msg{Message::make_from_document(document())}; msg)
|
auto msg{Message::make_from_document(mset_it_.get_document())};
|
||||||
|
if (msg)
|
||||||
return Some(std::move(msg.value()));
|
return Some(std::move(msg.value()));
|
||||||
else
|
else
|
||||||
return Nothing;
|
return Nothing;
|
||||||
|
@ -327,14 +325,15 @@ public:
|
||||||
std::unique_ptr<Message> unique_message_ptr() const {
|
std::unique_ptr<Message> unique_message_ptr() const {
|
||||||
return xapian_try(
|
return xapian_try(
|
||||||
[&]()->std::unique_ptr<Message> {
|
[&]()->std::unique_ptr<Message> {
|
||||||
return std::make_unique<Message>(Message(document()));
|
return std::make_unique<Message>(mset_it_.get_document());
|
||||||
}, nullptr);
|
}, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Xapian::MSetIterator mset_it_;
|
Xapian::MSetIterator mset_it_;
|
||||||
QueryMatches& query_matches_;
|
QueryMatches& query_matches_;
|
||||||
|
mutable Option<Mu::Document> document_;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr auto MaxQueryResultsSize = std::numeric_limits<size_t>::max();
|
constexpr auto MaxQueryResultsSize = std::numeric_limits<size_t>::max();
|
||||||
|
|
Loading…
Reference in New Issue