summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-30 09:40:05 +0530
committerArun Isaac2022-06-30 09:44:01 +0530
commitec07fe42fbfa900d981a48342e7bb3dba1e736f5 (patch)
tree80b06bb77b2dee343f864e07ae3b078c2cf6d65f
parent2dff868c30ebf8db172449822a5bcaf1ad52050e (diff)
downloadtissue-ec07fe42fbfa900d981a48342e7bb3dba1e736f5.tar.gz
tissue-ec07fe42fbfa900d981a48342e7bb3dba1e736f5.tar.lz
tissue-ec07fe42fbfa900d981a48342e7bb3dba1e736f5.zip
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.
-rw-r--r--tissue/search.scm66
1 files 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)))