OR condition failure

I have this query with the following conditions:

  1. Show blocks with DOING marker OR;
  2. Show blocks with TODO, DOING and is SCHEDULEd today OR;
  3. Show blocks with TODO, DOING and whose DEADLINE is today
#+BEGIN_QUERY
{:title      "πŸ“… **TODAY**"
 :query      [:find (pull ?b [*])
              :in $ ?today
              :where
              [?b :block/marker ?marker]
              [?b :block/page ?page]
              [?page :block/journal? true]
              (or 
                  [(= ?marker "DOING")]
                  [?b :block/scheduled ?date]
                  [?b :block/deadline ?date]
               )  ;; OR condition for "DOING" marker
              [(= ?date ?today)]
              [(contains? #{"NOW" "TODO" "LATER" "WAITING" "DOING"} ?marker)]]
 :inputs     [:today]
 :result-transform (fn [results]
                    (sort-by (fn [h]
                      (get h :block/priority "Z")) results))
 :collapsed? false
 :breadcrumb-show? false}

#+END_QUERY

However, the query shows nothing (see block highlighted in blue below):

What’s wrong with the query?

I rewrote the code. However, I still get no results

#+BEGIN_QUERY
{:title      "πŸ“… **TODAY**"
 :query      [:find (pull ?b [*])
              :in $ ?today
              :where
              [?b :block/marker ?marker]
              [?b :block/page ?page]
              [?page :block/journal? true]
              (or
                (and [?b :block/scheduled ?date]
                     [(= ?date ?today)])
                (and [?b :block/deadline ?date]
                     [(= ?date ?today)])
                [?b :block/marker "DOING"]) ;; Show "DOING" blocks regardless of date
              [(contains? #{"NOW" "TODO" "LATER" "WAITING" "DOING"} ?marker)]]
 :inputs     [:today]
 :result-transform (fn [results]
                    (sort-by (fn [h]
                      (get h :block/priority "Z")) results))
 :collapsed? false
 :breadcrumb-show? false}

#+END_QUERY
  • Your second effort was to the right direction, in moving [(= ?date ?today)] inside or
  • The missing step is to turn or into or-join [?b ?today]
2 Likes

Thanks.

For posterity, here is the query that satisfies these conditions:

#+BEGIN_QUERY
{:title      "πŸ“… **TODAY & DOING**"
 :query      [:find (pull ?b [*])
              :in $ ?today
              :where
              ;; Match blocks with a valid marker
              [?b :block/marker ?marker]
              ;; Match blocks in journal pages
              [?b :block/page ?page]
              [?page :block/journal? true]
              ;; Match blocks based on scheduled, deadline, or "DOING" marker
              (or-join [?b ?today]
                ;; Match blocks scheduled for today
                (and [?b :block/scheduled ?date]
                     [(= ?date ?today)])
                ;; Match blocks with a deadline for today
                (and [?b :block/deadline ?date]
                     [(= ?date ?today)])
                ;; Match blocks marked as "DOING"
                [?b :block/marker "DOING"])
              ;; Filter blocks with specific markers
              [(contains? #{"NOW" "TODO" "LATER" "WAITING" "DOING"} ?marker)]]
 :inputs     [:today]
 :result-transform (fn [results]
                     ;; Sort by priority, defaulting to "Z" for missing priority
                     (sort-by (fn [h] 
                                (get h :block/priority "Z")) 
                              results))
 :collapsed? false
 :breadcrumb-show? false}
#+END_QUERY

Happy Christmas everyone!:christmas_tree::sparkles::christmas_tree::sparkles::christmas_tree::sparkles:

1 Like