From 2ecd7f8d12e07bca7777e64bba0595e0ab34832d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 23 Nov 2017 10:34:52 +1300 Subject: [PATCH] Fix clamping of maxitems and time limit handling The maxitems argument to get_mset() was internally clamped to db.get_doccount() - corrected to db.get_doccount() - first. In practice this doesn't actually seem to cause any issues. When the match time limit expires, clamp check_at_least to first + maxitems instead of to maxitems. In practice this also doesn't seem to actually cause any issues (at least I've failed to construct a testcase where it actually makes an observable difference). --- xapian-core/api/enquire.cc | 4 ++-- xapian-core/matcher/multimatch.cc | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xapian-core/api/enquire.cc b/xapian-core/api/enquire.cc index a55af26fa..aeb632b40 100644 --- a/xapian-core/api/enquire.cc +++ b/xapian-core/api/enquire.cc @@ -282,9 +282,9 @@ Enquire::Internal::get_mset(doccount first, { Xapian::doccount docs = db.get_doccount(); first = min(first, docs); - maxitems = min(maxitems, docs); + maxitems = min(maxitems, docs - first); checkatleast = min(checkatleast, docs); - checkatleast = max(checkatleast, maxitems); + checkatleast = max(checkatleast, first + maxitems); } unique_ptr stats(new Xapian::Weight::Internal); diff --git a/xapian-core/matcher/multimatch.cc b/xapian-core/matcher/multimatch.cc index 3b50de705..5813f793c 100644 --- a/xapian-core/matcher/multimatch.cc +++ b/xapian-core/matcher/multimatch.cc @@ -219,7 +219,7 @@ MultiMatch::get_mset(Xapian::doccount first, Xapian::doccount maxitems, const Xapian::KeyMaker *sorter) { LOGCALL_VOID(MATCH, "MultiMatch::get_mset", first | maxitems | check_at_least | Literal("mset") | stats | Literal("mdecider") | Literal("sorter")); - AssertRel(check_at_least,>=,maxitems); + AssertRel(check_at_least,>=,first + maxitems); Assert(!query.empty()); @@ -402,8 +402,8 @@ MultiMatch::get_mset(Xapian::doccount first, Xapian::doccount maxitems, vsdoc.set_document(did); LOGLINE(MATCH, "Candidate document id " << did << " wt " << wt); Result new_item(wt, did); - if (check_at_least > maxitems && timeout.timed_out()) { - check_at_least = maxitems; + if (check_at_least > first + maxitems && timeout.timed_out()) { + check_at_least = first + maxitems; } if (sort_by != REL) { -- 2.11.4.GIT