From ed9aad811eae0dd8f2f992afd841b9f5e81481cd Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 29 Jun 2022 00:38:36 +0530 Subject: search: Limit number of search results. * tissue/search.scm (search-fold, search-map): Accept maximum number of search results and offset as arguments. * bin/tissue (tissue-search): Do not print number of search results. Use search-map instead of search-fold. --- bin/tissue | 6 +----- tissue/search.scm | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bin/tissue b/bin/tissue index ce6f4f7..7cc4a95 100755 --- a/bin/tissue +++ b/bin/tissue @@ -86,11 +86,7 @@ Search issues using SEARCH-QUERY. (args (call-with-database %xapian-index (lambda (db) - (format #t "total ~a~%" - (search-fold (lambda (document mset count) - (print document mset) - (1+ count)) - 0 db (string-join args)))))))) + (search-map print db (string-join args))))))) (define tissue-show (match-lambda* diff --git a/tissue/search.scm b/tissue/search.scm index ede23aa..f51bb95 100644 --- a/tissue/search.scm +++ b/tissue/search.scm @@ -25,7 +25,7 @@ #:export (search-fold search-map)) -(define (search-fold proc initial db search-query) +(define* (search-fold proc initial db search-query #:key (offset 0) (maximum-items 10)) "Search xapian database DB using SEARCH-QUERY and fold over the results using PROC and INITIAL. @@ -33,7 +33,11 @@ PROC is invoked as (PROC DOCUMENT MSET PREVIOUS). DOCUMENT is an instance of or one of its subclasses. MSET is the xapian MSet object representing the search results. PREVIOUS is the return from the previous invocation of PROC, or the given INITIAL for the -first call." +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 @@ -61,19 +65,24 @@ first call." result)) initial (enquire-mset (enquire db query) - #:maximum-items (database-document-count db))))) + #:maximum-items maximum-items)))) -(define (search-map proc db search-query) +(define* (search-map proc db search-query #:key (offset 0) (maximum-items 10)) "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 -representing the search results." +representing the search results. + +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." (reverse (search-fold (lambda (document mset result) (cons (proc document mset) result)) '() db - search-query))) + search-query + #:maximum-items maximum-items))) -- cgit v1.2.3