From e2fe50c591706a7902048aaef911ce433522a322 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 13 Jul 2022 13:27:30 +0530 Subject: document: Store serialized date as value in Xapian document. * tissue/document.scm (document-recency-date): Declare public generic function. (document-term-generator): Store serialized date in slot 0 of Xapian document. * tissue/file-document.scm (document-recency-date): New generic method. * tissue/commit.scm (document-recency-date): New generic method. --- tissue/commit.scm | 4 ++++ tissue/document.scm | 10 +++++++++- tissue/file-document.scm | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tissue/commit.scm b/tissue/commit.scm index 2ff6553..30d07b7 100644 --- a/tissue/commit.scm +++ b/tissue/commit.scm @@ -42,6 +42,10 @@ "Return the ID term for DOCUMENT." (string-append "Qcommit." (commit-hash commit))) +(define-method (document-recency-date (commit )) + "Return a date representing the recency of DOCUMENT" + (doc:commit-author-date commit)) + (define-method (document-term-generator (commit )) "Return a term generator indexing COMMIT." (let ((term-generator (next-method))) diff --git a/tissue/document.scm b/tissue/document.scm index ef3ca21..ecdabc3 100644 --- a/tissue/document.scm +++ b/tissue/document.scm @@ -37,6 +37,7 @@ document-type document-id-term document-text + document-recency-date document-term-generator document-snippet-source-text document-snippet @@ -133,6 +134,7 @@ that operates on a copy of OBJECT. It does not mutate OBJECT." (define-generic document-id-term) (define-generic document-text) +(define-generic document-recency-date) (define-generic print) (define-generic document->sxml) @@ -151,7 +153,13 @@ and further text, increase-termpos! must be called before indexing." #:document (make-document #:data (call-with-output-string (cut write (object->scm document) <>)) - #:terms `((,(document-id-term document) . 0)))))) + #:terms `((,(document-id-term document) . 0)) + ;; This serialization of the recency date gets + ;; the timezone ordering wrong. TODO: Replace it + ;; with sortable-serialise once it is working in + ;; guile-xapian. + #:values `((0 . ,(date->iso-8601 + (document-recency-date document)))))))) (index-text! term-generator (document-type document) #:prefix "XT") (index-text! term-generator (document-title document) #:prefix "S") (index-text! term-generator (document-text document)) diff --git a/tissue/file-document.scm b/tissue/file-document.scm index 112c7f2..1265660 100644 --- a/tissue/file-document.scm +++ b/tissue/file-document.scm @@ -64,6 +64,10 @@ "Return the ID term for DOCUMENT." (string-append "Qfile." (file-document-path document))) +(define-method (document-recency-date (document )) + "Return a date representing the recency of DOCUMENT." + (file-document-last-updated-date document)) + (define-method (document-text (document )) "Return the full text of DOCUMENT." (call-with-file-in-git (current-git-repository) (file-document-path document) -- cgit v1.2.3