From 3655b4ca24ff71a55ba119f30abba149e93cb43d Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 29 Jun 2022 00:29:28 +0530 Subject: search: Accept search query as a single string. * tissue/search.scm (search-fold, search-map): Accept search query as a single string instead of a list of strings. * bin/tissue (tissue-search): Pass a single search string to search-fold. * tissue/web/server.scm (handler): Pass a single search string to search-map. --- bin/tissue | 2 +- tissue/search.scm | 29 ++++++++++++----------------- tissue/web/server.scm | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/bin/tissue b/bin/tissue index d7d4424..ce6f4f7 100755 --- a/bin/tissue +++ b/bin/tissue @@ -90,7 +90,7 @@ Search issues using SEARCH-QUERY. (search-fold (lambda (document mset count) (print document mset) (1+ count)) - 0 db args))))))) + 0 db (string-join args)))))))) (define tissue-show (match-lambda* diff --git a/tissue/search.scm b/tissue/search.scm index 647ae5b..ede23aa 100644 --- a/tissue/search.scm +++ b/tissue/search.scm @@ -25,10 +25,9 @@ #:export (search-fold search-map)) -(define (search-fold proc initial db search-terms) - "Search xapian database DB using SEARCH-TERMS and fold over the -results using PROC and INITIAL. SEARCH-TERMS is a list of search terms -that are joined with the \"AND\" operator. +(define (search-fold proc initial db search-query) + "Search xapian database DB using SEARCH-QUERY and fold over the +results using PROC and INITIAL. PROC is invoked as (PROC DOCUMENT MSET PREVIOUS). DOCUMENT is an instance of or one of its subclasses. MSET is the xapian @@ -40,15 +39,12 @@ first call." ;; assume is:open. Assuming is:open is ;; implicitly assuming type:issue since only ;; issues can have is:open. - (if (every string-null? search-terms) + (if (string-null? search-query) "is:open" - (string-join (if (any (lambda (query-string) - (or (string-contains-ci query-string "type:") - (string-contains-ci query-string "is:"))) - search-terms) - search-terms - (cons "is:open" search-terms)) - " AND ")) + (if (or (string-contains-ci search-query "type:") + (string-contains-ci search-query "is:")) + search-query + (string-append "is:open " search-query))) #:stemmer (make-stem "en") #:prefixes '(("type" . "XT") ("title" . "S") @@ -67,10 +63,9 @@ first call." (enquire-mset (enquire db query) #:maximum-items (database-document-count db))))) -(define (search-map proc db search-terms) - "Search xapian database DB using SEARCH-TERMS and map over the results -using PROC. SEARCH-TERMS are a list of search terms that are joined -with the \"AND\" operator. +(define (search-map proc db search-query) + "Search xapian database DB using SEARCH-QUERY and map over the results +using PROC. PROC is invoked as (PROC DOCUMENT MSET). DOCUMENT is an instance of or one of its subclasses. MSET is the xapian MSet object @@ -81,4 +76,4 @@ representing the search results." result)) '() db - search-terms))) + search-query))) diff --git a/tissue/web/server.scm b/tissue/web/server.scm index c2b59e1..1a91810 100644 --- a/tissue/web/server.scm +++ b/tissue/web/server.scm @@ -143,7 +143,7 @@ to a stylesheet." (lambda (db) (search-map document->sxml db - (list (assoc-ref parameters "query"))))) + (assoc-ref parameters "query")))) css)))) (else (values (build-response #:code 404) -- cgit v1.2.3