Passing parameter values into a Query

Good day. New LogSeq user and loving it!
I created a simple search query that works just fine. However, now I want to pass in the search term from outside the query. Something like this:

searchTermVariable = “Business Architecture”
{{query (and searchTermVariable (between -3y today))}}

How do I do it?

Did you check out Dynamic Variables like <% current page %>?

Otherwise I guess you need to switch to advanced queries, which can receive query inputs via :inputs and have some more block-scoped dynamic variables like :query-page.

As said you can use advanced queries with dynamic input.

Make a block with just the search term and put the following query in a sub block under it.

#+BEGIN_QUERY
{:query [:find (pull ?b [*])
   :in $ ?t ?start ?end
   :where
     [?t :block/content ?term]
     [?b :block/content ?c]
     [(!= ?t ?b)]
     [(clojure.string/includes? ?c ?term)]
     [?b :block/page ?p]
     [?p :block/journal-day ?d]
     [(<= ?start ?d ?end)]
 ]
 :inputs [:parent-block :-3y :today]
}
#+END_QUERY

Result:

This is great! Thank you for your help.

1 Like