server: tweak sexp generation

This commit is contained in:
Dirk-Jan C. Binnema 2023-08-05 11:08:11 +03:00
parent 4945e699c8
commit 01a516f0d3
1 changed files with 15 additions and 11 deletions

View File

@ -174,24 +174,28 @@ append_metadata(std::string& str, const QueryMatch& qmatch)
* A message here consists of a message s-expression with optionally a :docid * A message here consists of a message s-expression with optionally a :docid
* and/or :meta expression added. * and/or :meta expression added.
* *
* Note, for speed reasons, we build is as a _string_, without any further * We could parse the sexp and use the Sexp APIs to add some things... but...
* parsing. * it's _much_ faster to directly work on the string representation: remove the
* final ')', add a few items, and add the ')' again.
*/ */
static std::string static std::string
msg_sexp_str(const Message& msg, Store::Id docid, const Option<QueryMatch&> qm) msg_sexp_str(const Message& msg, Store::Id docid, const Option<QueryMatch&> qm)
{ {
auto sexpstr{msg.document().sexp_str()}; auto&& sexpstr{msg.document().sexp_str()};
sexpstr.reserve(sexpstr.size () + (docid == 0 ? 0 : 16) + (qm ? 64 : 0));
// remove the closing ( ... ) if (docid != 0 || qm) {
sexpstr.erase(sexpstr.end() - 1); sexpstr.reserve(sexpstr.size () + (docid == 0 ? 0 : 16) + (qm ? 64 : 0));
if (docid != 0) // remove the closing ( ... )
sexpstr += " :docid " + to_string(docid); sexpstr.erase(sexpstr.end() - 1);
if (qm)
append_metadata(sexpstr, *qm);
sexpstr += ')'; // ... end close it again. if (docid != 0)
sexpstr += " :docid " + to_string(docid);
if (qm)
append_metadata(sexpstr, *qm);
sexpstr += ')'; // ... end close it again.
}
return sexpstr; return sexpstr;
} }