From ec07fe42fbfa900d981a48342e7bb3dba1e736f5 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 30 Jun 2022 09:40:05 +0530 Subject: search: Separate out query parsing into public function. * tissue/search.scm: Import parse-query from (xapian xapian) renaming it to xapian:parse-query. (parse-query): New public function. (search-fold): Use parse-query. --- tissue/search.scm | 66 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/tissue/search.scm b/tissue/search.scm index 18bdb73..1aafc40 100644 --- a/tissue/search.scm +++ b/tissue/search.scm @@ -21,10 +21,36 @@ #:use-module (tissue document) #:use-module (tissue issue) #:use-module (xapian wrap) - #:use-module (xapian xapian) - #:export (search-fold + #:use-module ((xapian xapian) #:renamer (lambda (symbol) + (case symbol + ((parse-query) 'xapian:parse-query) + (else symbol)))) + #:export (parse-query + search-fold search-map)) +(define (parse-query search-query) + "Parse SEARCH-QUERY and return a xapian Query object." + (xapian:parse-query + ;; When query does not mention type or state, assume + ;; is:open. Assuming is:open is implicitly assuming type:issue + ;; since only issues can have is:open. + (if (string-null? search-query) + "is:open" + (if (or (string-contains-ci search-query "type:") + (string-contains-ci search-query "is:")) + search-query + (string-append "is:open AND (" search-query ")"))) + #:stemmer (make-stem "en") + #:prefixes '(("type" . "XT") + ("title" . "S") + ("creator" . "A") + ("lastupdater" . "XA") + ("assigned" . "XI") + ("keyword" . "K") + ("tag" . "K") + ("is" . "XS")))) + (define* (search-fold proc initial db search-query #:key (offset 0) (maximum-items (database-document-count db))) "Search xapian database DB using SEARCH-QUERY and fold over the @@ -39,34 +65,14 @@ first call. OFFSET specifies the number of items to ignore at the beginning of the result set. MAXIMUM-ITEMS specifies the maximum number of items to return." - (let ((query (parse-query - ;; When query does not mention type or state, - ;; assume is:open. Assuming is:open is - ;; implicitly assuming type:issue since only - ;; issues can have is:open. - (if (string-null? search-query) - "is:open" - (if (or (string-contains-ci search-query "type:") - (string-contains-ci search-query "is:")) - search-query - (string-append "is:open AND (" search-query ")"))) - #:stemmer (make-stem "en") - #:prefixes '(("type" . "XT") - ("title" . "S") - ("creator" . "A") - ("lastupdater" . "XA") - ("assigned" . "XI") - ("keyword" . "K") - ("tag" . "K") - ("is" . "XS"))))) - (mset-fold (lambda (item result) - (proc (call-with-input-string (document-data (mset-item-document item)) - (compose scm->object read)) - (MSetIterator-mset-get item) - result)) - initial - (enquire-mset (enquire db query) - #:maximum-items maximum-items)))) + (mset-fold (lambda (item result) + (proc (call-with-input-string (document-data (mset-item-document item)) + (compose scm->object read)) + (MSetIterator-mset-get item) + result)) + initial + (enquire-mset (enquire db (parse-query search-query)) + #:maximum-items maximum-items))) (define* (search-map proc db search-query #:key (offset 0) (maximum-items (database-document-count db))) -- cgit v1.2.3