xapian: Collapse results for merged issues.
authorRicardo Wurmus <rekado@elephly.net>
Thu, 14 May 2020 07:28:15 +0000 (09:28 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Thu, 14 May 2020 07:28:15 +0000 (09:28 +0200)
mumi/xapian.scm

index e4fd316f47c3da64ce9944bbe2639c2ecd2a57b2..925f67bba9f8df981d46ed5ef4db117bcac396b4 100644 (file)
@@ -98,7 +98,15 @@ messages and index their contents in the Xapian database at DBPATH."
                                       #:terms `((,idterm . 0))
                                       #:values
                                       `((0 . ,(or (and date (date->string date "~Y~m~d")) "19700101"))
-                                        (1 . ,(or (and mdate (date->string mdate "~Y~m~d")) "19700101")))))
+                                        (1 . ,(or (and mdate (date->string mdate "~Y~m~d")) "19700101"))
+                                        ;; This is used for collapsing search results
+                                        (2 . ,(let ((merged (bug-mergedwith bug)))
+                                                (if merged
+                                                    (string-join
+                                                     (sort (cons bugid (string-split merged #\space))
+                                                           string<)
+                                                     " ")
+                                                    bugid))))))
                   (term-generator (make-term-generator #:stem (make-stem "en")
                                                        #:document doc)))
              ;; Index fields with a suitable prefix. This allows for
@@ -261,16 +269,19 @@ intact."
                                       token))
                                 (tokenize querystring))))
              ;; Parse querystring passing a stemmer and suitable
-            ;; prefixes for field search.
-            (query (parse-query* querystring*
-                                 #:stemmer (make-stem "en")
-                                 #:prefixes '(("submitter" . "A")
-                                              ("author"    . "XA")
-                                              ("subject"   . "S")
-                                              ("owner"     . "XO")
-                                              ("severity"  . "XS")
-                                              ("tag"       . "XT")
-                                              ("status"    . "XSTATUS")))))
+             ;; prefixes for field search.
+             (query (parse-query* querystring*
+                                  #:stemmer (make-stem "en")
+                                  #:prefixes '(("submitter" . "A")
+                                               ("author"    . "XA")
+                                               ("subject"   . "S")
+                                               ("owner"     . "XO")
+                                               ("severity"  . "XS")
+                                               ("tag"       . "XT")
+                                               ("status"    . "XSTATUS"))))
+             (enq (enquire db query)))
+        ;; Collapse on mergedwith value
+        (Enquire-set-collapse-key enq 2 1)
         ;; Fold over the results, return bug id.
         (mset-fold (lambda (item acc)
                      (cons
@@ -280,7 +291,7 @@ intact."
                    ;; Get an Enquire object from the database with the
                    ;; search results. Then, extract the MSet from the
                    ;; Enquire object.
-                   (enquire-mset (enquire db query)
+                   (enquire-mset enq
                                  #:maximum-items pagesize))))))
 
 (define* (index! #:key full?)