Subject: [PATCH 2/7] xapian: Declare some prefixes as boolean.

From: Arun Isaac <[email-masked]>
Date: Thu, 29 Dec 2022 20:23:55 +0000

Some prefixes will only ever be used to filter the rest of the query
and not for matching approximately using relevance weighting
schemes. Such prefixes should be indexed as boolean prefixes.

* mumi/xapian.scm (parse-query*): Support boolean prefixes.
(search): Declare author, msgid, owner, severity, status, submitter
and tag as boolean prefixes.
---
 mumi/xapian.scm | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/mumi/xapian.scm b/mumi/xapian.scm
index 06a54cd..7bf84d3 100644
--- a/mumi/xapian.scm
+++ b/mumi/xapian.scm
@@ -249,7 +249,7 @@ messages and index their contents in the Xapian database at DBPATH."
         (invalid (pk invalid "")))
       token))
 
-(define* (parse-query* querystring #:key stemmer stemming-strategy (prefixes '()))
+(define* (parse-query* querystring #:key stemmer stemming-strategy (prefixes '()) (boolean-prefixes '()))
   (let ((queryparser (new-QueryParser))
         (date-range-processor (new-DateRangeProcessor 0 "date:" 0))
         (mdate-range-processor (new-DateRangeProcessor 1 "mdate:" 0)))
@@ -261,6 +261,10 @@ messages and index their contents in the Xapian database at DBPATH."
                 ((field . prefix)
                  (QueryParser-add-prefix queryparser field prefix)))
               prefixes)
+    (for-each (match-lambda
+                ((field . prefix)
+                 (QueryParser-add-boolean-prefix queryparser field prefix)))
+              boolean-prefixes)
     (QueryParser-add-rangeprocessor queryparser date-range-processor)
     (QueryParser-add-rangeprocessor queryparser mdate-range-processor)
     (let ((query (QueryParser-parse-query queryparser querystring
@@ -324,14 +328,14 @@ intact."
              ;; 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")
-                                               ("msgid"     . "XU"))))
+                                  #:prefixes '(("subject" . "S"))
+                                  #:boolean-prefixes '(("author"    . "XA")
+                                                       ("msgid"     . "XU")
+                                                       ("owner"     . "XO")
+                                                       ("severity"  . "XS")
+                                                       ("status"    . "XSTATUS")
+                                                       ("submitter" . "A")
+                                                       ("tag"       . "XT"))))
              (enq (enquire db query)))
         ;; Collapse on mergedwith value
         (Enquire-set-collapse-key enq 2 1)
-- 
2.38.1