I need some help to remove the tasks that are present in Today’s Journal Page from the query, and to improve my query overall
I’ve been wrestling with Advanced queries in Logseq and could really use some help. Despite diving into the material and trying out Siferiax’s tutorials, I’m still struggling to grasp the syntax. Coming from an art background, it’s been particularly challenging for me to wrap my head around it all.
After weeks of effort, I’ve managed to put together the following query, but I’m hitting a wall and could use some guidance:
Thanks for the points, mentaloid!
I really appreciate that you went beyond to try to help me
I’ve tried your query but it was still showing the #ignore tasks, and I was thinking of excluding the tasks that are on today’s journal, and not tasks created today, but again thanks for help.
Sorry for the confuse description! I’ve re-wrote it in plain english to try to make it clearer:
Task Check:
It scans all tasks across pages and journals.
Filtering by Status:
Only tasks with TODO, DOING, WAITING, or LATER markers are included.
Priority A Override:
Tasks marked with Priority A are always shown, regardless of the criteria below.
Date-Based Filtering:
Tasks with schedules or deadlines equal to or earlier than today are included.
Excluding Today’s Journal:
Tasks in today’s journal page are ignored.
Excluding Future-Scheduled Tasks:
Tasks scheduled for the future are excluded.
Tag Filtering:
Only tasks tagged with #Tasks are considered.
Excluding Ignored Tasks:
Tasks with the #ignore tag are ignored.
Organizing by Priority:
Tasks are organized by priority for clear visibility.
Still with a few redundancies and somewhat ambiguous (e.g. I don’t get how a task in today’s journal is not created today), but otherwise very helpful. This attempt is commented:
#+BEGIN_QUERY
{
:title [:h2 " 📝Task Scraper"]
:query [:find (pull ?block [*])
:in $ ?today ?start
:where ; scan everywhere for all
[?block :block/marker ?marker] ; blocks of specific markers
[(contains? #{"NOW" "LATER" "TODO" "DOING" "WAITING"} ?marker)]
(or-join [?block ?today ?start] ; which are either
[?block :block/priority "A"] ; any top-priority blocks
(and ; or blocks that are
(not ; not
[?block :block/path-refs ?br1]
[?br1 :block/name "ignore"] ; ignored
)
[?block :block/path-refs ?br2]
[?br2 :block/name "tasks"] ; tasks
(or-join [?block ?today] ; and either
(and
[?block :block/scheduled ?sd] ; scheduled for
[(<= ?sd ?today)] ; before tomorrow
)
(and ; or
[?block :block/deadline ?dd] ; ending
[(<= ?dd ?today)] ; before tomorrow
)
)
(not ; but not
[?block :block/created-at ?d] ; created
[(>= ?d ?start)] ; today
)
)
)
]
:inputs [:today :today-start]
:result-transform (fn [result]
(sort-by
(fn [h]
(get h :block/priority "Z")
)
result
)
)
:collapsed? false
:breadcrumb-show? false
}
#+END_QUERY
I made some slight changes.
I don’t think the query was really that redundant, at least when looking at the criteria for it.
I’m going to take the criteria at face value and so changed the created at to just, lives on today’s journal.
And I included those tasks that are not scheduled and not deadlined. I think those were to be included as well.
#+BEGIN_QUERY
{
:title [:h2 " 📝Task Scraper"]
:query [:find (pull ?block [*])
:in $ ?today
:where ; scan everywhere for all
[?block :block/marker ?marker] ; blocks of specific markers
[(contains? #{"LATER" "TODO" "DOING" "WAITING"} ?marker)]
(or-join [?block ?today] ; which are either
[?block :block/priority "A"] ; any top-priority blocks
(and ; or blocks that are
[?block :block/path-refs ?br2]
[?br2 :block/name "tasks"] ; tasks
(not ; not
[?block :block/path-refs ?br1]
[?br1 :block/name "ignore"] ; ignored
)
(or-join [?block ?today] ; and either
(and
[?block :block/scheduled ?sd] ; scheduled for
[(<= ?sd ?today)] ; before tomorrow
)
(and ; or
[?block :block/deadline ?dd] ; ending
[(<= ?dd ?today)] ; before tomorrow
)
;or not scheduled and not deadlined
(not
[?block :block/scheduled ?sd]
[?block :block/deadline ?dd]
)
)
(not ; but not
[?block :block/page ?j] ; Located on page
[?j :block/journal-day ?today] ; today's journal
)
)
)
]
:inputs [:today]
:result-transform (fn [result]
(sort-by
(fn [h]
(get h :block/priority "Z")
)
result
)
)
:collapsed? false
:breadcrumb-show? false
}
#+END_QUERY
Still with a few redundancies and somewhat ambiguous (e.g. I don’t get how a task in today’s journal is not created today), but otherwise very helpful. This attempt is commented:
mentaloid, i’ve tested your query but for some reason it didn’t worked as expected, it ended just showing the the A priorities tasks and forgot all the other ones. I’m really grateful for your time and efforts toward this
Siferiax, your query almost worked out-of-the box !! For some reason I had to disable the
[?block :block/deadline ?dd]
to make it work properly, if i kept it in the code it would show scheduled tasks for the future, so I make it as a comment and the query it’s already functional, since I do not use the deadline function.
But I’m so close to the final result that it makes me super happy
This is what i’ve done, took the Siferiax approach and added a comment on the line mentioned
#+BEGIN_QUERY
{
:title [:h6 " 📝Task Scraper"]
:query [:find (pull ?block [*])
:in $ ?today
:where ; scan everywhere for all
[?block :block/marker ?marker] ; blocks of specific markers
[(contains? #{"LATER" "TODO" "DOING" "WAITING"} ?marker)]
(or-join [?block ?today] ; which are either
[?block :block/priority "A"] ; any top-priority blocks
(and ; or blocks that are
[?block :block/path-refs ?br2]
[?br2 :block/name "tasks"] ; tasks
(not ; not
[?block :block/path-refs ?br1]
[?br1 :block/name "ignore"] ; ignored
)
(or-join [?block ?today] ; and either
(and
[?block :block/scheduled ?sd] ; scheduled for
[(<= ?sd ?today)] ; before tomorrow
)
(and ; or
[?block :block/deadline ?dd] ; ending
[(<= ?dd ?today)] ; before tomorrow
)
;or not scheduled and not deadlined
(not
[?block :block/scheduled ?sd]
;[?block :block/deadline ?dd] ; Made the fix here to make it work
)
)
(not ; but not
[?block :block/page ?j] ; Located on page
[?j :block/journal-day ?today] ; today's journal
)
)
)
]
:inputs [:today]
:result-transform (fn [result]
(sort-by
(fn [h]
(get h :block/priority "Z")
)
result
)
)
:collapsed? false
:breadcrumb-show? false
}
#+END_QUERY
Glad it has been useful.
I think, from the top of my head, that the problem in the not statement is actually that it is not the same variable. And actually you don’t need a variable there at all.
So it would just be: