如何在 emacs 中实现 pdf 全文搜索?

一直采用 org-ref 来管理参考文献,现在文件夹里面有 300+ 个 pdf 文件。请教一下各位,有什么方法能够快速实现对多个 pdf 文件的全文搜索吗?

2 个赞

我用 snails:

(require 'snails-core)

(snails-create-async-backend
 :name
 "searchablepdf"

 :build-command
 (lambda (input)
     (when (and (executable-find "rga")
                (> (length input) 2))
       (list "rga" "--no-heading" "--column" "--color" "never" "--max-columns" "300" input (expand-file-name "/PATH/PDF/DO/YOUR/SELF/"))))

 :candidate-filter
 (lambda (candidate-list)
   (let (candidates)
     (dolist (candidate candidate-list)
       (let ((candidate-info (split-string candidate ":")))
         (snails-add-candiate
          'candidates
          (format "%s: %s"
                  (snails-format-line-number (nth 0 candidate-info) snails-start-buffer-lines)
                  (string-join (cddr candidate-info)))
          candidate)))
     candidates))

 :candiate-do
 (lambda (candidate)
         (let ((file-info (split-string candidate ":")))
           (when (> (length file-info) 2)
             (if (get-buffer (concat (nth 0 file-info) ":" (nth 1 file-info))) (kill-buffer (concat (nth 0 file-info) ":" (nth 1 file-info))))
             (org-pdfview-open (concat (nth 0 file-info) ":" (nth 1 file-info)))
             (pdf-view-goto-page (string-to-number (substring (nth 3 file-info) 5)))
             (snails-flash-line)))))

(provide 'snails-backend-searchablepdf)
1 个赞

欢迎贡献后端到Snails的主分支. :wink:

哇,被 snail 作者抓住了. :innocent:

下周花一些时间完善一下, 我尽力.

snails支持@分隔符形式的目录输入, 你不用把pdf的目录写死。

它会根据用户输入的目录动态的去找文件