summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorArun Isaac2022-06-25 15:46:49 +0530
committerArun Isaac2022-06-25 16:04:08 +0530
commite3bc61d00c8de8a5a618d28cb87a69fe30e7dad8 (patch)
tree07cb9e4d408d6be9283fdfe4dce809ab9a3a5a34 /bin
parent223df46be51d641279f98ff5f9cb6a9b477e09c6 (diff)
downloadtissue-e3bc61d00c8de8a5a618d28cb87a69fe30e7dad8.tar.gz
tissue-e3bc61d00c8de8a5a618d28cb87a69fe30e7dad8.tar.lz
tissue-e3bc61d00c8de8a5a618d28cb87a69fe30e7dad8.zip
bin: Add search subcommand.
* bin/tissue (tissue-show): New function.
(print-usage): List search subcommand.
(main): Call tissue-search.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tissue50
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/tissue b/bin/tissue
index 85f18b9..862f807 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -219,6 +219,54 @@ List issues.
                                rcount
                                (issues)))))))
 
+(define tissue-search
+  (match-lambda*
+    (("--help")
+     (format #t "Usage: ~a search SEARCH-QUERY
+Search issues using SEARCH-QUERY.
+
+"))
+    (args
+     (call-with-database %xapian-index
+       (lambda (db)
+         (let* ((stemmer (make-stem "en"))
+                (query-string (string-join args))
+                (query (parse-query
+                        ;; If issue state is not mentioned in query,
+                        ;; assume is:open.
+                        (if (string-contains-ci query-string "is:")
+                            query-string
+                            (format #f "is:open AND (~a)" query-string))
+                        #:stemmer stemmer
+                        #:prefixes '(("title" . "S")
+                                     ("creator" . "A")
+                                     ("last-updater" . "XA")
+                                     ("updater" . "XA")
+                                     ("assigned" . "XI")
+                                     ("keyword" . "K")
+                                     ("tag" . "K")
+                                     ("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 ((snippet (mset-snippet (MSetIterator-mset-get item)
+                                                               (call-with-input-file (issue-file issue)
+                                                                 get-string-all)
+                                                               #:length 200
+                                                               #:highlight-start (color 'BOLD 'ON-RED)
+                                                               #:highlight-end (color 'RESET)
+                                                               #:stemmer stemmer)))
+                                    (unless (string-null? snippet)
+                                      (display snippet)
+                                      (newline)
+                                      (newline)))
+                                  (1+ count)))
+                              0
+                              (enquire-mset (enquire db query)
+                                            #:maximum-items (database-document-count db))))))))))
+
 (define tissue-show
   (match-lambda*
     (("--help")
@@ -326,6 +374,7 @@ Export the repository as a website to OUTPUT-DIRECTORY.
 
 COMMAND must be one of the sub-commands listed below:
 
+  search    search issues
   list      list issues
   show      show the text of an issue
   repl      run a Guile script in a tissue environment
@@ -386,6 +435,7 @@ top-level of the git repository."
                        (WritableDatabase-set-metadata db "commit" current-head))))))
              ;; Handle sub-command.
              (apply (match command
+                      ("search" tissue-search)
                       ("list" tissue-list)
                       ("show" tissue-show)
                       ("repl" tissue-repl)