Hi, please modify this Logseq query to exclude notes which name contains "Template":…
- User
Hi, please modify this Logseq query to exclude notes which name contains "Template":
#+BEGIN_QUERY { :title [:b "TODO"] ;; ---- Get every block into variable ?block :query [:find (pull ?block [*]) ;; ---- filter command :where ;; ---- get block content into variable ?blockcontent [?block :block/content ?blockcontent] ;; ---- get page (special type of block) into variable ?page (used later) [?block :block/page ?page] ;; ---- get page name (lowercase) from the page block into variable ?pagename [?page :block/name ?pagename] ;; ---- get block marker (TODO LATER ETC) into variable ?marker [?block :block/marker ?marker] ;; ---- Select block if it has one or more tasks (TODO or DONE etc) [(contains? #{"TODO"} ?marker)] ;; ---- Exclude block if it has one or more tasks (not [(contains? #{"DOING"} ?marker)]) ] } #+END_QUERY
- Assistant
To exclude notes which have "Template" in their name, you'd need to add a clause that checks the
?pagenamevariable and ensures it does not contain the string "Template". You can do so by using thenotandclojure.string/includes?functions together withclojure.string/lower-caseto make sure the comparison is case-insensitive. Here is how your updated query should look:#+BEGIN_QUERY { :title [:b "TODO"] :query [:find (pull ?block [*]) :where [?block :block/content ?blockcontent] [?block :block/page ?page] [?page :block/name ?pagename] [?block :block/marker ?marker] [(contains? #{"TODO"} ?marker)] (not [(contains? #{"DOING"} ?marker)]) ;; Check if the page name does not contain "Template" ;; Convert page name to lowercase before comparison (not [(clojure.string/includes? (clojure.string/lower-case ?pagename) "template")]) ] } #+END_QUERYIn this updated query, I've added the last two lines before the closing for the clause. These lines filter out any pages where the name includes "Template", regardless of the capitalization of the characters in the page name. The use of ensures that both and the string "template" are in lowercase, allowing for a case-insensitive comparison.
- User
Getting this error: "Join variables should not be empty"
- Assistant
I apologize for the confusion earlier. The error "Join variables should not be empty" suggests that the inner part of the join, i.e., the
notclause, lacks a binding to join on, which is essential for matching patterns in Datalog, the query language used by Logseq.Since you're looking to filter out pages based on their names, we can approach the query with direct filtering using the
notandclojure.string/includes?functions, as mentioned before. Here's the revised query:#+BEGIN_QUERY { :title [:b "TODO"] :query [:find (pull ?block [*]) :where [?block :block/content ?blockcontent] [?block :block/page ?page] [?page :block/name ?pagename] [?block :block/marker ?marker] ;; Include blocks only if they are marked with "TODO" [(contains? #{"TODO"} ?marker)] ;; Exclude blocks that are marked with "DOING" (not [(contains? #{"DOING"} ?marker)]) ;; Ensure page name does not contain "Template" (case-insensitive check) (not [(clojure.string/includes? (clojure.string/lower-case ?pagename) "template")]) ] :result-transform (fn [result] (filter #(some? (second %)) result)) } #+END_QUERY - User
Sorry, it says "Invalid query".
- Assistant
I apologize for the oversight. In Logseq's Datalog query system, functions like
clojure.string/includes?are not directly usable within the:whereclause. We need to use Logseq's built-in functions or rules to achieve what you need.Let's modify the
:whereclause to use the predicates correctly:#+BEGIN_QUERY { :title [:b "TODO"] :query [:find (pull ?block [*]) :in $ ?excluded-name :where [?block :block/content ?blockcontent] [?block :block/page ?page] [?page :block/name ?pagename] [?block :block/marker ?marker] ;; Ensure the task is a TODO, not a DOING [(contains? #{"TODO"} ?marker)] (not [(contains? #{"DOING"} ?marker)]) ;; Exclude pages with "Template" in the name (not [(?pagename ?excluded-name)])] :args ["Template"] } #+END_QUERY - User
Getting Block REnder Error. Also this string got added at the start of the query: "query-table:: false"
- Assistant
I apologize for the previous missteps. I will now correct the query considering the limitations of Logseq's datalog query functionalities. Here is the revised version that should work for you:
#+BEGIN_QUERY { :title [:b "TODO"] :query [:find (pull ?block [*]) :where [?block :block/marker ?marker] [(contains? #{"TODO"} ?marker)] ;; get the reference to the page of the block [?block :block/page ?page] ;; find the name of the page [?page :block/name ?name] ;; filter out pages that contain "Template" in the name; this is case sensitive (not [(re-find #"(?i).*Template.*" ?name)])] } #+END_QUERYIn this query,
re-findis used with a regex pattern that includes(?i)to make the match case-insensitive. This will match any occurrence of the term "Template" within the page name and exclude those pages from the results.Make sure to copy this query exactly as it appears into your Logseq editor, and let me know if you encounter any more issues.
- User
Sigh, invalid query again.
- Assistant
My sincerest apologies for the continued confusion. Writing queries for Logseq using the right syntax can be tricky due to the specific features and limitations of the system. Let's try another approach for your query using Logseq's query syntax without regex or unsupported string functions.
Here's an updated query that filters out pages with the name containing the word "Template":
#+BEGIN_QUERY { :title [:b "TODO"] :query [:find (pull ?block [*]) :where ;; get block content into variable ?blockcontent [?block :block/content ?blockcontent] ;; get the reference to the page of the block [?block :block/page ?page] ;; find the name of the page [?page :block/name ?pagename] ;; find the marker of the block (TODO, DONE, etc.) [?block :block/marker ?marker] ;; include the block if it's marked as TODO [(contains? #{"TODO"} ?marker)] ;; exclude blocks that are currently marked as DOING (not [(contains? #{"DOING"} ?marker)]) ;; exclude pages with the name containing "Template" (not [(re-matches (re-pattern "(?i).*template.*") ?pagename)])] } #+END_QUERY - User
Block render error again...
- Assistant
I apologize for the back and forth, and I appreciate your patience. In Logseq, regular expressions and string operations are not readily available in the Datalog queries by default, which is why you're experiencing difficulty with the previous examples. It appears that Logseq has not provided support for such functions out-of-the-box in the Datalog queries.
Here's an alternative approach that may help you. The solution is to add a custom property to your pages that do not contain "Template" in their title and then query for pages with that property. This is a manual workaround since the current Logseq querying system doesn't support string matching within the clause as one might expect from other querying languages.
- User
Can we do this the other way around? What if I add the property to the template?
- Assistant
Absolutely, adding a property to your template pages is a more efficient approach as it allows you to mark these pages specifically and then exclude them in your query based on the presence of that property.
First, add a property to each template page. You can call the property something like
templateand set its value totrue. In each template's front-matter, add:--- template: true ---Once you've added this property to all your template pages, you can adjust the query to exclude any pages where the
templateproperty is set totrue. Here's the modified query:#+BEGIN_QUERY { :title [:b "TODO"] :query [:find (pull ?block [*]) :where [?block :block/marker ?marker] [(contains? #{"TODO"} ?marker)] [?block :block/page ?page] ;; make sure we get pages without the template property set to true [?page :block/properties ?props] (not [(get ?props "template") true])] } #+END_QUERY - User
Let's start from scratch. How to select all TODO tasks with a Logseq query embedded in a note but exclude pages which have Template in their name?
- Assistant
Certainly! To accomplish this, we'll write a query to fetch all blocks marked with "TODO" and then exclude pages with "Template" in their names. As of the last information I have, Logseq cannot directly filter based on matching substrings in page titles within the query language itself.
- User
Let's start from scratch again. How to select all TODO tasks with a Logseq query embedded in a note but exclude pages which have task_name in their contents?
- Assistant
To select all TODO tasks except the ones on pages that include a specific term (e.g.,
task_name) in their contents, you would use a Logseq query with a filtering condition. As of my latest knowledge, direct content matching or string searching in queries within a Logseq note may not be supported.However, there might be a workaround by using block properties. If the pages you are trying to exclude have a distinct property that you can query against, such as a tag or a specific front-matter property, then you can write a query to exclude them on that basis.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.