From a2080ebf931d8c31da8c6f31770b309e15fdf70e Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 29 Dec 2022 20:24:00 +0000 Subject: xapian: Preserve order of search results. Xapian orders search results by relevance. Preserve this order. * mumi/xapian.scm (search): Reverse search results after consing to preserve the original order. * mumi/messages.scm (status-with-cache): Do not sort bugs by their bug number. Preserve the order of bugs passed to this function. --- mumi/messages.scm | 13 ++++--------- mumi/xapian.scm | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/mumi/messages.scm b/mumi/messages.scm index b3ae962..fd52571 100644 --- a/mumi/messages.scm +++ b/mumi/messages.scm @@ -64,15 +64,10 @@ (define (status-with-cache ids) "Invoke GET-STATUS, but only on those IDS that have not been cached yet. Return new results alongside cached results." - (let* ((cached (filter-map cached? ids)) - (uncached-ids (lset-difference eq? - ids - (map bug-num cached))) - (new (filter-map bug-status uncached-ids ))) - ;; Cache new things - (map (lambda (bug) (cache! (bug-num bug) bug)) new) - ;; Return everything from cache - (sort (append cached new) (lambda (a b) (< (bug-num a) (bug-num b)))))) + (map (lambda (id) + (or (cached? id) + (cache! id (bug-status id)))) + ids)) (define (extract-name address) (or (assoc-ref address 'name) diff --git a/mumi/xapian.scm b/mumi/xapian.scm index ae01acc..7ca5bb8 100644 --- a/mumi/xapian.scm +++ b/mumi/xapian.scm @@ -339,16 +339,17 @@ intact." ;; Collapse on mergedwith value (Enquire-set-collapse-key enq 2 1) ;; Fold over the results, return bug id. - (mset-fold (lambda (item acc) - (cons - (document-data (mset-item-document item)) - acc)) - '() - ;; Get an Enquire object from the database with the - ;; search results. Then, extract the MSet from the - ;; Enquire object. - (enquire-mset enq - #:maximum-items pagesize)))))) + (reverse + (mset-fold (lambda (item acc) + (cons + (document-data (mset-item-document item)) + acc)) + '() + ;; Get an Enquire object from the database with the + ;; search results. Then, extract the MSet from the + ;; Enquire object. + (enquire-mset enq + #:maximum-items pagesize))))))) (define* (index! #:key full?) "Index all Debbugs log files corresponding to the selected -- cgit v1.2.3