How to exclude tasks from today Journal from my Adv. QUERY?

Hey everyone,

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:

#+BEGIN_QUERY
{
 :title [:h2 " 📝Task Scraper"]
 :query [:find (pull ?block [*])
          :in $ ?today ?start
          :where
          [?b :block/created-at ?d]
          [(>= ?d ?start)]
          (or-join [?block ?today]
                   (and
                    [?block :block/marker ?marker]
                    [(contains? #{"NOW" "LATER" "TODO" "DOING" "WAITING"} ?marker)]
                    (or
                     (and [?block :block/scheduled ?d]
                          (or [(<= ?d ?today)]
                              ))
                     (and [?block :block/deadline ?d]
                          (or [(<= ?d ?today)]
                              ))))
                   (and
                    [?block :block/marker ?marker]
                    [(contains? #{"NOW" "LATER" "TODO" "DOING" "WAITING"} ?marker)]
					[?block :block/path-refs [:block/name "tasks"]]
                    (not [?block :block/scheduled])
					(not [?block :block/deadline])
                    (not [?block :block/path-refs [:block/name "ignore"]]))
                   )]
 :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

My goal was to create a query that follows this logic:

  • AND(
    • IS TODO, DOING, WAITING, LATER
    • OR(
      • OR (
        • Priority A
        • Schedule <= Today
        • Deadline <= Today
        • )
      • AND (
        • #Tasks tag
        • NOT Scheduled
        • NOT Deadline
        • NOT #ignore tag
        • NOT in Today Journal
        • )
      • )
    • )

I feel like I’m close, but something’s not quite clicking. Any suggestions or pointers would be greatly appreciated!

Welcome.

  • The provided query doesn’t run.
  • The provided logic doesn’t follow any known syntax.
  • I hardly make sense of your description.
  • You should rather:
    • prepare small queries that actually work
      • let us fix and clarify those first
    • describe their desired combination in plain English
      • avoid formal logical statements that you don’t fully understand
    • let us prepare for you the desired combination in Datalog
  • Anyway, after:
    • plenty of assumptions
    • much guesswork
    • a few fixes
    • many simplifications
  • …I have come up with the following untested attempt, for whatever it’s worth:
    #+BEGIN_QUERY
    {
     :title [:h2 " 📝Task Scraper"]
     :query [:find (pull ?block [*])
       :in $ ?today ?start
       :where
         [?block :block/marker ?marker]
         [(contains? #{"NOW" "LATER" "TODO" "DOING" "WAITING"} ?marker)]
         (or-join [?block ?today ?start]
           [?block :block/priority "A"]
           (and
             [?block :block/scheduled ?d]
             [(<= ?d ?today)]
           )
           (and
             [?block :block/deadline ?d]
             [(<= ?d ?today)]
           )
           (and
             [?block :block/path-refs ?br]
             [?br :block/name "tasks"]
             (not [?block :block/scheduled])
             (not [?block :block/deadline])
             (not
               [?block :block/path-refs ?br]
               [?br :block/name "ignore"]
             )
             (not
               [?block :block/created-at ?d]
               [(>= ?d ?start)]
             )
           )
         )
     ]
     :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
    
1 Like

Thanks for the points, mentaloid! :smiley:
I really appreciate that you went beyond to try to help me :heart:

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.


Hope that this makes things clearer :person_raising_hand:

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
1 Like

@talesrt @mentaloid

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
1 Like

:heart: Thanks a Lot Folks! :heart:
You Guys Rocks

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 :smiling_face:

Siferiax, your query almost worked out-of-the box :rocket:!! 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 :slight_smile:

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
1 Like

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:

(not
  [?block :block/scheduled]
  [?block :block/deadline]
)

So, it doesn’t have any scheduled and any deadline.
but if you don’t use deadline, you can just remove deadline all together. :slight_smile:

1 Like

@Siferiax

It worked Like a Charm! Tnx so much!

1 Like