summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-30 10:07:56 +0530
committerArun Isaac2022-06-30 10:10:54 +0530
commit9926be311b099650e369270297727dd94ffbd794 (patch)
tree16be5f9500e674399823802b7bfd06dda2373320
parentec07fe42fbfa900d981a48342e7bb3dba1e736f5 (diff)
downloadtissue-9926be311b099650e369270297727dd94ffbd794.tar.gz
tissue-9926be311b099650e369270297727dd94ffbd794.tar.lz
tissue-9926be311b099650e369270297727dd94ffbd794.zip
web: server: Display estimated number of matches.
* tissue/web/server.scm: Import (xapian wrap). Import parse-query from (xapian xapian) renaming it to xapian:parse-query. (make-search-page): Display estimated number of matches. (handler): Pass estimated number of matches to make-search-page.
-rw-r--r--tissue/web/server.scm40
1 files changed, 30 insertions, 10 deletions
diff --git a/tissue/web/server.scm b/tissue/web/server.scm
index 10ef95e..0002866 100644
--- a/tissue/web/server.scm
+++ b/tissue/web/server.scm
@@ -28,7 +28,11 @@
#:use-module (web response)
#:use-module (web server)
#:use-module (web uri)
- #:use-module (xapian xapian)
+ #:use-module (xapian wrap)
+ #:use-module ((xapian xapian) #:renamer (lambda (symbol)
+ (case symbol
+ ((parse-query) 'xapian:parse-query)
+ (else symbol))))
#:use-module (tissue conditions)
#:use-module (tissue document)
#:use-module (tissue search)
@@ -128,9 +132,10 @@ a.tag-chore {
color: black;
}")
-(define (make-search-page results query css)
- "Return SXML for a page with search RESULTS produced for QUERY. CSS is
-a URI to a stylesheet."
+(define (make-search-page results query estimated-matches css)
+ "Return SXML for a page with search RESULTS produced for
+QUERY. ESTIMATED-MATCHES is the estimated number of matches. CSS is a
+URI to a stylesheet."
`(html
(head
(title "Tissue search")
@@ -171,6 +176,9 @@ operators "
(span (@ (class "search-filter"))
"OR")
"."))
+ (p "Found an estimated "
+ (strong ,(string-append (number->string estimated-matches))
+ " results"))
(ul ,@results))))
(define (query-parameters query)
@@ -200,12 +208,24 @@ to a stylesheet."
"")))
(values '((content-type . (text/html)))
(sxml->html
- (make-search-page
- (call-with-database xapian-index
- (lambda (db)
- (search-map document->sxml db search-query)))
- search-query
- css)))))
+ (call-with-database xapian-index
+ (lambda (db)
+ (let ((mset (enquire-mset (enquire db (parse-query search-query))
+ #:offset 0
+ #:maximum-items (database-document-count db))))
+ (make-search-page
+ (reverse
+ (mset-fold (lambda (item result)
+ (cons (document->sxml
+ (call-with-input-string (document-data (mset-item-document item))
+ (compose scm->object read))
+ mset)
+ result))
+ '()
+ mset))
+ search-query
+ (MSet-get-matches-estimated mset)
+ css))))))))
(else
(values (build-response #:code 404)
(string-append "Resource not found: "