diff mbox series

[bug#60410,7/7] xapian: Preserve order of search results.

Message ID 20221229202400.28565-7-arunisaac@systemreboot.net
State New
Headers show
Series mumi: Boolean prefixes in xapian indexing and others | expand

Commit Message

Arun Isaac Dec. 29, 2022, 8:24 p.m. UTC
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 mbox series

Patch

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