diff options
author | Arun Isaac | 2022-06-26 23:34:05 +0530 |
---|---|---|
committer | Arun Isaac | 2022-06-27 00:19:51 +0530 |
commit | ef47614b81052f2a2758ad26c194a44a8ce441c6 (patch) | |
tree | 9d49021f9f11bac73f58f20b84581597e8cca0b7 /bin | |
parent | c424794720dc1ada9274c5363fd201d6eeae4b0f (diff) | |
download | tissue-ef47614b81052f2a2758ad26c194a44a8ce441c6.tar.gz tissue-ef47614b81052f2a2758ad26c194a44a8ce441c6.tar.lz tissue-ef47614b81052f2a2758ad26c194a44a8ce441c6.zip |
tissue: Generalize issue-files to indexed-documents.
* tissue/tissue.scm (<tissue-configuration>)[issue-files]: Delete
field.
[indexed-documents]: New field.
* tissue/tissue.scm (tissue-configuration): Remove issue-files
argument. Add indexed-documents argument.
* bin/tissue: Import (tissue document) with doc: prefix.
(print-document, alist->document, document->text, index-document): New
functions.
(tissue-search): Display search results for generalized documents
using print-document, alist->document and document->text.
(main): Index generalized documents using index-document.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/tissue | 49 |
1 files changed, 42 insertions, 7 deletions
@@ -38,6 +38,7 @@ exec guile --no-auto-compile -s "$0" "$@" (xapian wrap) (xapian xapian) (tissue conditions) + (prefix (tissue document) doc:) (tissue git) (tissue issue) (tissue tissue) @@ -92,6 +93,14 @@ to run tissue." (match (command-line) ((program _ ...) program))) +(define (print-document document) + "Print DOCUMENT, an <issue> or <document> object." + ((cond + ((issue? document) print-issue) + ((doc:document? document) doc:print-document) + (else (raise (unknown-document-type-violation document)))) + document)) + (define (print-issue issue) "Print ISSUE." (let ((number-of-posts (length (issue-posts issue)))) @@ -165,6 +174,23 @@ to run tissue." (newline) (newline))) +(define (alist->document alist) + "Convert ALIST to an <issue> or <document> object." + ((case (assq-ref alist 'type) + ((issue) alist->issue) + ((document) doc:alist->document) + (else (raise (unknown-document-type-violation alist)))) + alist)) + +(define (document->text document) + "Return the text of DOCUMENT, an <issue> or <document> object." + (call-with-input-file + ((cond + ((issue? document) issue-file) + ((doc:document? document) doc:document-file) + (else (raise (unknown-document-type-violation document)))) + document) + get-string-all)) (define tissue-search (match-lambda* @@ -203,12 +229,11 @@ Search issues using SEARCH-QUERY. ("is" . "XS"))))) (format #t "total ~a~%" (mset-fold (lambda (item count) - (let ((issue (call-with-input-string (document-data (mset-item-document item)) - (compose alist->issue read)))) - (print-issue issue) + (let ((document (call-with-input-string (document-data (mset-item-document item)) + (compose alist->document read)))) + (print-document document) (let ((snippet (mset-snippet (MSetIterator-mset-get item) - (call-with-input-file (issue-file issue) - get-string-all) + (document->text document) #:length 200 #:highlight-start (color 'BOLD 'ON-RED) #:highlight-end (color 'RESET) @@ -349,6 +374,15 @@ top-level of the git repository." (negate (cut member <> (list "." ".."))))) (rmdir %xapian-index))) +(define (index-document db document) + "Index DOCUMENT, an <issue> or <document> object, in writable xapian +DB." + ((cond + ((issue? document) index-issue) + ((doc:document? document) doc:index-document) + (else (raise (unknown-document-type-violation document)))) + db document)) + (define main (match-lambda* ((_ (or "-h" "--help")) @@ -382,8 +416,9 @@ top-level of the git repository." (delete-xapian-index) (call-with-writable-database %xapian-index (lambda (db) - (for-each (cut index-issue db <>) - (issues)) + (for-each (lambda (indexed-document) + (index-document db ((indexed-document-reader indexed-document)))) + (tissue-configuration-indexed-documents (load-config))) (WritableDatabase-set-metadata db "commit" current-head)))))) ;; Handle sub-command. (apply (match command |