Skip to main content
Calling tracker sparql query via D-Bus Asynchronous and showing the results in a dired buffer
Source Link
;;
    (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
                )
    )
  )
;;
    (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
                  "' }")
              )
      )
;;
    (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
                )
    )
  )
Source Link

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
                  "' }")
              )
      )