diff options
author | Arun Isaac | 2022-06-29 00:38:36 +0530 |
---|---|---|
committer | Arun Isaac | 2022-06-29 00:46:28 +0530 |
commit | ed9aad811eae0dd8f2f992afd841b9f5e81481cd (patch) | |
tree | 4aa197f7fddd37a18982c3b643b4d2b590245710 | |
parent | 3655b4ca24ff71a55ba119f30abba149e93cb43d (diff) | |
download | tissue-ed9aad811eae0dd8f2f992afd841b9f5e81481cd.tar.gz tissue-ed9aad811eae0dd8f2f992afd841b9f5e81481cd.tar.lz tissue-ed9aad811eae0dd8f2f992afd841b9f5e81481cd.zip |
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.
-rwxr-xr-x | bin/tissue | 6 | ||||
-rw-r--r-- | tissue/search.scm | 21 |
2 files changed, 16 insertions, 11 deletions
@@ -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 <document> 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 <document> 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))) |