From b0cf99385a73b7461789aae2d71f7ad23ab5c56f Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 9 Jul 2022 15:34:31 +0530 Subject: document: Make snippet source text extraction a generic function. * tissue/document.scm (document-snippet-source-text): New generic method. (document-html-snippet): Use document-snippet-source-text. --- tissue/document.scm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tissue/document.scm b/tissue/document.scm index 983a1f2..e40c80e 100644 --- a/tissue/document.scm +++ b/tissue/document.scm @@ -40,6 +40,7 @@ document-id-term document-text document-term-generator + document-snippet-source-text document-snippet print document-sxml-snippet @@ -178,15 +179,21 @@ and further text, increase-termpos! must be called before indexing." (index-text! term-generator (file-document-path document)) term-generator)) +(define-method (document-snippet-source-text (document )) + "Return the source text for DOCUMENT from which to extract a search +result snippet." + ;; Remove blank lines from document text. + (string-join + (remove (cut string-every char-set:whitespace <>) + (string-split (document-text document) + #\newline)) + "\n")) + (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 - (string-join - (remove (cut string-every char-set:whitespace <>) - (string-split (document-text document) - #\newline)) - "\n") + (document-snippet-source-text document) #:length 200 #:highlight-start "" #:highlight-end "" -- cgit v1.2.3