summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorArun Isaac2022-07-04 00:32:37 +0530
committerArun Isaac2022-07-04 17:28:20 +0530
commit719bf34be42a0156d194f17bd76c2ef94fb424b3 (patch)
tree391a20a3b8d42734fc7e5faf34b59b7cfcec3e1d /bin
parent02c19cf48d9ddc36286a7b7527795f46ca647c11 (diff)
downloadtissue-719bf34be42a0156d194f17bd76c2ef94fb424b3.tar.gz
tissue-719bf34be42a0156d194f17bd76c2ef94fb424b3.tar.lz
tissue-719bf34be42a0156d194f17bd76c2ef94fb424b3.zip
bin: Separate out indexing into new function.
* bin/tissue (index): New function. (main): Use index.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tissue56
1 files changed, 30 insertions, 26 deletions
diff --git a/bin/tissue b/bin/tissue
index bcc85f9..60e3769 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -304,6 +304,34 @@ To get usage information for one of these sub-commands, run
(negate (cut member <> (list "." "..")))))
(rmdir directory)))
+(define (index db-path)
+ "Index current repository into xapian database at DB-PATH. If DB-PATH
+already exists and is up to date, do nothing."
+ (let ((current-head
+ (oid->string (reference-name->oid (current-git-repository) "HEAD"))))
+ (unless (and (file-exists? db-path)
+ (string=? (call-with-database db-path
+ (cut Database-get-metadata <> "commit"))
+ current-head))
+ (guard (c (else (delete-directory db-path)
+ (format (current-error-port)
+ "Building xapian index failed.~%")
+ (raise c)))
+ (delete-directory db-path)
+ (call-with-writable-database db-path
+ (lambda (db)
+ (for-each (lambda (indexed-document)
+ (let* ((document (slot-set ((indexed-document-reader indexed-document))
+ 'web-uri
+ (indexed-document-web-uri indexed-document)))
+ (term-generator (document-term-generator document)))
+ (index-text! term-generator (document-type document) #:prefix "XT")
+ (replace-document! db
+ (document-id-term document)
+ (TermGenerator-get-document term-generator))))
+ (tissue-configuration-indexed-documents (load-config)))
+ (WritableDatabase-set-metadata db "commit" current-head)))))))
+
(define main
(match-lambda*
((_ (or "-h" "--help"))
@@ -318,32 +346,8 @@ To get usage information for one of these sub-commands, run
;; Create hidden tissue directory unless it exists.
(unless (file-exists? %state-directory)
(mkdir %state-directory))
- ;; Ensure index exists rebuilding it if it is stale.
- (let ((current-head
- (oid->string (reference-name->oid
- (current-git-repository) "HEAD"))))
- (unless (and (file-exists? %xapian-index)
- (string=? (call-with-database %xapian-index
- (cut Database-get-metadata <> "commit"))
- current-head))
- (guard (c (else (delete-directory %xapian-index)
- (display "Building xapian index failed."
- (current-error-port))
- (raise c)))
- (delete-directory %xapian-index)
- (call-with-writable-database %xapian-index
- (lambda (db)
- (for-each (lambda (indexed-document)
- (let* ((document (slot-set ((indexed-document-reader indexed-document))
- 'web-uri
- (indexed-document-web-uri indexed-document)))
- (term-generator (document-term-generator document)))
- (index-text! term-generator (document-type document) #:prefix "XT")
- (replace-document! db
- (document-id-term document)
- (TermGenerator-get-document term-generator))))
- (tissue-configuration-indexed-documents config))
- (WritableDatabase-set-metadata db "commit" current-head))))))
+ ;; Ensure index exists, rebuilding it if it is stale.
+ (index %xapian-index)
;; Handle sub-command.
(apply (match command
("search" tissue-search)