I use Gnome Tracker quite a bit and am led to wonder whether there is currently any way to use Tracker from within emacs? That is to say; searching for files indexed by Tracker, within emacs (and consequently reading them with pdf-tools or docview). It would be one less reason to fire up the Tracker Desktop Search interface.
-
1Does it come with a command line interface? In this case, it should be relatively straight forward to write a little emacs interface. I did the same for KDE's Baloo using helm: github.com/malb/emacs.d/blob/master/…– Martin R. AlbrechtCommented Apr 30, 2017 at 13:33
-
@MartinR.Albrecht, yes it does have a fairly good command line interface; the CLI is better than the GUI in a sense and what you have done there for Baloo is what I am looking for Tracker. Thanks for the nice pointer; I will try to put together something useful!– Vishal BelsareCommented Apr 30, 2017 at 20:09
-
1I would love to see what you've come up with @VishalBelsare. THis would be great for me to have too!– MattCommented Jun 23, 2017 at 4:09
-
@Matt just seeing your comment. I did not do much with Martin's suggestion, with the exception of a bare bones function which calls tracker. I will post that as an answer.– Vishal BelsareCommented Sep 14, 2017 at 22:20
-
@Matt, please see the function 'tracker-dbus-async'. While a lot more could be done, this is a little more useful than before. I want to add the FTS snippets in the display also, but I don't know enough to integrate the that information in a dired buffer.– Vishal BelsareCommented Dec 26, 2017 at 23:44
2 Answers
Looking at Martin's link to using baloo under KDE, the following function calls tracker's sparql query and shows the results in a new frame. A lot more needs to be done and could be added to make this really useful. The results are shown in a file URI format, and find-file-at-point works to open the documents in DocView mode. I use this mainly to use full-text search over a collection of PDF articles (and some ODT/DOCX files). More information could be displayed by modifying the sparql query. I'd love to add something akin to org-mode's hyperlink file display, i.e. return the list of files displaying just the filename and hiding the file URI in the hyperlink - would save column space.
;;
(defun tracker-sparql (sparql-query)
(start-process "tracker-sparql" "tracker-sparql" "tracker" "sparql" "-q" sparql-query)
(switch-to-buffer-other-frame "tracker-sparql")
)
(defun tracker (search-term)
(interactive "sFulltext Search String: ")
(tracker-sparql (concat "SELECT nie:url(?f) WHERE { ?f fts:match '"
search-term
"' }")
)
)
(require 'dbus)
(defun tracker-dbus-async (search-terms)
(interactive "sFulltext Search String: ")
;; mapcar 'car --> mapcar 'url-file-truename --> dired cons
(defun tracker-results-process (search-terms results)
(dired (cons
(concat "Tracker Search: " search-terms)
(mapcar (lambda (x) (url-file-truename (car x))) results)
))
)
(fset 'tracker-results-process-fix-search-terms
(apply-partially 'tracker-results-process search-terms))
(let ((search-query (concat "SELECT nie:url(?f) WHERE {
?f a nfo:Document . ?f fts:match '" search-terms "'
} ORDER BY
DESC (fts:rank(?f))")))
;; search-query
(dbus-call-method-asynchronously
:session "org.freedesktop.Tracker1"
"/org/freedesktop/Tracker1/Resources"
"org.freedesktop.Tracker1.Resources"
"SparqlQuery"
'tracker-results-process-fix-search-terms
search-query
)
)
)
Some years ago I wrote a dired-based interface to tracker results. It's not polished, but in case it is of any use, you can find the code here: https://www.emacswiki.org/emacs/Tracker