From efec16853cce7a497010a2da42844a7bc0bd704f Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 29 Jun 2022 11:48:03 +0530 Subject: document: Abstract out HTML snippet generation. * tissue/document.scm (document-html-snippet): New function. (document-snippet, document-sxml-snippet): Use document-html-snippet. --- tissue/document.scm | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'tissue/document.scm') diff --git a/tissue/document.scm b/tissue/document.scm index 2806f3b..b549f2d 100644 --- a/tissue/document.scm +++ b/tissue/document.scm @@ -173,17 +173,22 @@ and further text, increase-termpos! must be called before indexing." (index-text! term-generator (file-document-path document)) term-generator)) +(define (document-html-snippet document mset) + "Return snippet for DOCUMENT. MSET is the xapian MSet object +representing a list of search results." + (mset-snippet mset + (document-text document) + #:length 200 + #:highlight-start "" + #:highlight-end "" + #:stemmer (make-stem "en"))) + (define (document-snippet document mset) "Return snippet for DOCUMENT. MSET is the xapian MSet object representing a list of search results." - ;; mset-snippet returns serialized HTML. So, we reverse it with - ;; html->sxml. - (match (html->sxml (mset-snippet mset - (document-text document) - #:length 200 - #:highlight-start "" - #:highlight-end "" - #:stemmer (make-stem "en"))) + ;; mset-snippet, and thus document-html-snippet, returns serialized + ;; HTML. So, we reverse it with html->sxml. + (match (html->sxml (document-html-snippet document mset)) (('*TOP* children ...) (string-join (map (match-lambda @@ -211,14 +216,9 @@ MSet object representing a list of search results." (define (document-sxml-snippet document mset) "Return snippet in SXML form for DOCUMENT. MSET is the xapian MSet object representing a list of search results." - ;; mset-snippet returns serialized HTML. So, we reverse it with - ;; html->sxml. - (match (html->sxml (mset-snippet mset - (document-text document) - #:length 200 - #:highlight-start "" - #:highlight-end "" - #:stemmer (make-stem "en"))) + ;; mset-snippet, and thus document-html-snippet, returns serialized + ;; HTML. So, we reverse it with html->sxml. + (match (html->sxml (document-html-snippet document mset)) (('*TOP* children ...) (append-map (lambda (child) (cond -- cgit v1.2.3