From cbc176b9bb02c2c136695a7d2321d840781decfd Mon Sep 17 00:00:00 2001 From: Wander Nauta Date: Tue, 18 Aug 2026 21:12:00 +0200 Subject: [PATCH 1/2] adapt LockedSqw to upstream changes in sqlwriter See https://github.com/berthubert/sqlitewrite/commit/5e291af887d57a0541d6777d3dcc0d1915db4d11 --- sws.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sws.hh b/sws.hh index ca22f30..1272d6c 100644 --- a/sws.hh +++ b/sws.hh @@ -33,12 +33,12 @@ struct LockedSqw return packResultsJson(result); } - void addValue(const std::initializer_list>& values, const std::string& table="data") + void addValue(const std::initializer_list>& values, const std::string& table="data") { std::lock_guard l(sqwlock); sqw.addValue(values, table); } - void addValue(const std::vector>& values, const std::string& table="data") + void addValue(const std::vector>& values, const std::string& table="data") { std::lock_guard l(sqwlock); sqw.addValue(values, table); @@ -117,10 +117,10 @@ struct SimpleWebSystem { return sws.getIP(req); } - void log(const std::initializer_list>& fields) + void log(const std::initializer_list>& fields) { // add agent? - std::vector> values{{"user", user}, {"ip", getIP()}, {"tstamp", time(0)}}; + std::vector> values{{"user", user}, {"ip", getIP()}, {"tstamp", time(0)}}; for(const auto& f : fields) values.push_back(f); lsqw.addValue(values, "log"); From 2659f5745541aff6b93eb4522c1646d61e62877e Mon Sep 17 00:00:00 2001 From: Wander Nauta Date: Tue, 18 Aug 2026 22:54:16 +0200 Subject: [PATCH 2/2] indicate search result itemlimit truncation in UI This is based on #140, but with a slight twist; the item limit is still not documented because I imagine it is not guaranteed and may change in future, but the response does now indicate whether truncation has happened. This is also exposed to the user interface, which recommends asking a more specific query. The total number of matches is not computed. --- html/logic.js | 7 ++++++- partials/search.html | 4 ++-- tkserv.cc | 13 ++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/html/logic.js b/html/logic.js index 21fb224..2980c37 100644 --- a/html/logic.js +++ b/html/logic.js @@ -306,7 +306,12 @@ async function getSearchResults(f) rssurl.searchParams.set("q", f.searchQuery); f.rssurl = rssurl.href; - f.message = `< ${Math.ceil(data["milliseconds"])} milliseconden`; + if (data["truncated"]) { + f.message = `De nieuwste ${f.foundDocs.length} resultaten worden getoond - probeer een specifiekere zoekvraag.`; + } else { + f.message = `${f.foundDocs.length} resultaten in < ${Math.ceil(data["milliseconds"])} milliseconden`; + } + f.busy=false; orderByDate(f, false); } diff --git a/partials/search.html b/partials/search.html index 64ae48b..48902d7 100644 --- a/partials/search.html +++ b/partials/search.html @@ -115,9 +115,9 @@ -
+ -
+ {% endblock %} diff --git a/tkserv.cc b/tkserv.cc index a9a899c..f3fc602 100644 --- a/tkserv.cc +++ b/tkserv.cc @@ -2238,6 +2238,7 @@ int main(int argc, char** argv) dt.start(); int mseclimit = 10000; + int itemlimit = 280; shared_ptr uc = s_uc; @@ -2258,7 +2259,14 @@ int main(int argc, char** argv) fmt::print("Categories: {}\n", categories); - auto sres = sh.search(term, categories, limit, mseclimit, 280); + auto sres = sh.search(term, categories, limit, mseclimit, itemlimit + 1); + bool truncated = false; + + if (sres.size() > itemlimit) { + sres.pop_back(); + truncated = true; + } + nlohmann::json results = nlohmann::json::array(); for(const auto& r : sres) { @@ -2283,13 +2291,16 @@ int main(int argc, char** argv) })); } + // soorten! auto usec = dt.lapUsec(); fmt::print("Got {} matches in {} msec\n", results.size(), usec/1000.0); g_stats.searchUsec += usec; nlohmann::json response=nlohmann::json::object(); + response["results"]= results; + response["truncated"] = truncated; response["milliseconds"] = usec/1000.0; res.set_content(response.dump(), "application/json");