Hi all,
I am struggling with building a query for searching my meeting notes. I could not find a working solution that fits all my needs yet. I am not sure if this is even possible. I want to post this question here because I am sure your understanding of queries in Logseq is way better than mine.
What I want to achieve:
I make meeting notes in my journal as child blocks under e.g. #Meeting1
. When searching my meeting notes, I want to find:
- the blocks
#Meeting1
- that contain one or more
searchString
anywhere in this block or in child blocks - I also want to see the page (or the date of the page), that block is on, sorted by date
What I tried:
Simple query
{{query (and [[Meeting1]] "SearchString")}}
This query finds all blocks, that are under a block that references #Meeting1
and contains SearchString
. The results are not ordered by date. When I switch to table view, I can sort by pagename (format: Wednesday, 05.03.2025). But this only sorts by the first letter of the weekday. Also, this shows the block where the SearchString
appears, not the #Meeting1
block.
{{query (and [[Meeting1]] "SearchString" "SearchString2")}}
If I add a second SearchString2
, the results only show blocks that contain both search strings. But I also want to see the block that has both search strings somewhere in its children.
Advanced query
I believe I can solve this by creating an advanced query. I managed to build one that finds the blocks that are linked to the page Meeting1
.
#+BEGIN_QUERY
{:title "Testquery"
:query [:find (pull ?h [*])
:in $ ?current
:where
[?h :block/refs ?r]
[?r :block/name ?current]]
:inputs ["[[Meeting1]]"]
:collapsed? false}
#+END_QUERY
And I found a way to build a query that finds a string in the block content.
#+BEGIN_QUERY
{:title "Testquery String"
:query [:find (pull ?b [*])
:in $ ?string
:where
[?b :block/content ?c]
[(not= ?string "")]
[(re-pattern ?string) ?q]
[(re-find ?q ?c)]]
:inputs ["searchString"]
:collapsed? false}
#+END_QUERY
I don’t know how to combine the two to limit the results from the first query to all blocks that contain a searchString
itself or one of its children.
I hope you can give me a hint.
Thank you very much in advance.
Gregor