Convenient queries with property values as input?

Hi all,

I use complex queries in logseq to search for strings in my meeting notes, for example.

It is inconvenient to always open the query code to change the strings, that are used as input.

Therefore, I am curious if it is possible to connect values outside of the query with the input variables. This could be page properties of a known page or block content of a block with a known UUID.

Porperty on Testpage

Example Query:

#+BEGIN_QUERY
{:title "Suche alle Blöcke, die einen Suchbegriff enthalten"
 :inputs ["Testbegriff"]
 :query [:find (pull ?b [*])
         :in $ ?string1
         :where
         [?b :block/content ?c]
         [(not= ?string1 "")]
         [(re-pattern ?string1) ?q]
         [(re-find ?q ?c)]]
 :collapsed? false}
#+END_QUERY

Do you know how I can use the value of the property “string1” on “Testpage” as input value for the variable “string1” in my query?

  • Cannot pass it in :inputs
  • But can read it at the beginning of :where , e.g.:
    [?p :block/original-name "Testpage"]
    [?p :block/properties ?props]
    [(get ?props :string1) ?string1]  
    
    • This approach covers the majority of needs.
      • Some complicated values cannot be produced in Datalog, they need scripting.
1 Like

Perfect, thanks a lot. The query now looks as follows:

#+BEGIN_QUERY
{:title "Suche alle Blöcke, die einen Suchbegriff enthalten"
 :query [:find (pull ?b [*])
         :where
         [?p :block/original-name "Testpage"]
         [?p :block/properties ?props]
         [(get ?props :string1) ?string1] 
         [?b :block/content ?c]
         [(not= ?string1 "")]
         [(re-pattern ?string1) ?q]
         [(re-find ?q ?c)]]
 :collapsed? false}
#+END_QUERY

It finds all blocks that contain a string that is defined in the page property “string1” of “Testpage”. The property is forbidden to be empty to not query all block.