Open EFLS opened 3 years ago
You can search for a string within certain date boundaries, but beyond that there is no structured search of org documents.
The thing is, org-mode is a rather slow piece of software, and do not open files in org-mode while searching, to keep it fast. This means we can't do agenda-like structured searches in org-journal documents.
However, you can use org-mode's Agenda to search in a slower, but more powerful way, as detailed in the README.
The thing is, org-mode is a rather slow piece of software, and do not open files in org-mode while searching, to keep it fast.
That makes sense, thanks for your reply.
I'll explore using org-ql to retrieve search results and put them in a separate buffer, as an alternative to org-agenda, which should be faster. I'll share my results here later on.
I'll be very interested in your findings! Search speed of course also varies with the size of the journal, but I've never actually run a benchmark on how fast org-journal searches are in comparison with agenda searches.
I've created something that does what I want, more or less. It feels a bit hacky though.
This function leverages org-ql
to return a list of markers to all subtrees containing a search string.
(defun efls/org-journal-ql-search (str)
"Search org-journal files for str and return markers to found entries."
(require 'org-ql)
(let (markers)
; For org subtree...
(dolist (entry
; ... that contains the STR (as found by org-ql) ...
(org-ql-select (org-journal--list-files)
`(regexp ,str)
:action 'element-with-markers))
; ... get a marker to it and return the resulting list
(push (plist-get (nth 1 entry) ':org-marker) markers))
markers))
The second function is the user-facing one. It prompts for a search string and builds a new buffer with search results. I tried to include dates entries fall under, but this is the part that feels a bit hacky, both because of the assumptions it makes about how journal files are structured (i.e., dates with subtrees containing entries), and because of how it retrieves the contents.
(defun efls/org-journal-gather-entries (str)
"Build a buffer with org-journal entries containing STR."
(interactive (list (read-string "Search for: ")))
(switch-to-buffer "*org-journal-test-buffer*")
(erase-buffer)
(org-mode)
(insert "#+title: Results for " str "\n")
(let ((results (efls/org-journal-ql-search str)))
; For each of the markers found...
(dolist (marker results)
; copy date and contents
(let (date contents)
(with-temp-buffer
(org-goto-marker-or-bmk marker)
(org-narrow-to-subtree)
(setq contents (buffer-string))
(widen)
; assuming parent entry is the date
(org-up-element)
(setq date (org-get-heading t t t)))
(switch-to-buffer "*org-journal-test-buffer*")
(insert "* " date "\n" contents "\n")))))
Anyway, it seems to work. The first time it is called, the search takes a while as org-ql opens all the files in org-journal--list-files
. But subsequent searches seem really fast.
Org-journal has grown on me, and I can't imagine my journaling without it. Currently, I mix all types of journal entries together (e.g., work related & personal) and I differentiate between them by adding plain text
#tags
. This allows me to easily retrieve all entries with a specific tag thanks to the search function.Now to make this even better, I'd like to generate a new buffer with all entries containing
#tag
. From such a buffer, one could read or export journal entries. Is this a sensible feature request?I know of
org-journal-schedule-view
to generate a buffer, andorg-journal-search
to show search results. Is there an easy way to combine the two? Or do you have any pointers on how to achieve something like this?Feel free to dismiss my suggestion/question if it doesn't fit Org-journal's scope.