References with specific tag or task

I am new to Logseq and this query langauge is very confusing to me.

Goal: To have a query on each page for a person that has a list of discussion topics collected from notes around my graph. I am very close, and I have something worked up that seems to work okay for looking for TODO items, but it’s not quite right and I believe there are some index caching issues with my use of :current-page. I want to adjust this to also include blocks that have a #discuss tag on them, because i realize I don’t want to make TODO items for all of my dicussion topics as it makes my other task tracking messy.

Here is what I have going on right now:

First, I have a testing page that has a references a couple of people, has a tagged discussion item, and a TODO discussion item.

image

Here is the query I am using for both the John Doe and Jane Doe pages:

#+BEGIN_QUERY
{:title [:h3 "Discussion Topics"]
 :query [
         :find (pull ?b [*])
         :in $ ?currentpage
         :where
         (page-ref ?b ?currentpage)
         (task ?b #{"NOW" "LATER" "TODO" "DOING"})
       ]
 :inputs [:current-page]}
#+END_QUERY

For John Doe, it shows my TODO item for “Jane Doe”, even though “John Doe” is not in that TODO block. I am not sure why this happens other than to assume it’s being pulled from the parent block? I don’t know how to fix this.

image

For Jane Doe, the current query appears to work as expected, except I do not know how to also add in the block with the #discuss tag.

image

With all things remaining the same (besides the query of course) I want to get to where my “John Doe” page has nothing listed (I don’t have any discussion items for him) and my “Jane Doe” page has two items listed (the tagged item and the TODO item).

I think that (hopefully) gets you everything you need to know about what I am trying to do, and where I am currently at. Thanks for any assistance you may have for me!

Welcome.

  • Your example doesn’t properly follow your requirements.
  • If your actual requirement is to get “all topics to discuss with the current person”, you just need the parent of the block that contains #discuss and [[current person]] :
    #+BEGIN_QUERY
    {:title [:h3 "Discussion Topics"]
     :query [
         :find (pull ?b [*])
         :in $ ?current-name
         :where
             [?current-page :block/name ?current-name]
             [?discuss :block/name "discuss"]
             [?child :block/refs ?current-page]
             [?child :block/refs ?discuss]
             [?child :block/parent ?b]
     ]
     :inputs [:current-page]
    }
    #+END_QUERY
    

Thanks for the help.

The parent may not be related at all to the actual block that I have flagged to discuss with someone. In fact, that is specifically the use case I am trying to address here.

So in your query, John Doe’s seems right, because there is nothing for him, but when I put it on the Jane Doe page, I get the parent bullet regarding John Doe, which does not belong here. It does get me the two discussion items for Jane tho, so this is definetely an improvement. However it also puts in any block that even mentions Jane Doe even if there is no TODO or #discuss tag.

I have tried to find a simple reference for how to do advanced queries, but I have yet to find one where someone goes through the syntax. I thought I found one, then it got confusing because it seems like there are two different types of syntax for queries and I was ending up mixing and matching them in a way that wasn’t productive for learning.

If I wrote this in pseudo code - which I am way better at :wink: - this is what I am trying to do

Find any block on any page
Get the current-page title and assign it to the variable for “current name”
Then list any blocks that have “current name” and ALSO #discuss OR TODO in the same block.

Does that better explain what I am trying to do? There is no association to parent/child in my requirement.

But this is the topic to #discuss in the scheduled TODO, since the title of the query is “Discussion Topics”! Besides, if we query only the children, their parent block will appear anyway (unless shown in table view). Try this one:

#+BEGIN_QUERY
{:title [:h3 "Discussion Topics"]
 :query [
     :find (pull ?b [*])
     :in $ ?current-name
     :where
         [?current-page :block/name ?current-name]
         [?discuss :block/name "discuss"]
         [?b :block/refs ?current-page]
         (or-join [?b ?discuss]
             [?b :block/refs ?discuss]
             (and
                 [?b :block/marker ?marker]
                 [(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
             )
         )
 ]
 :inputs [:current-page]
}
#+END_QUERY

I don’t know what the title of the query has to do with anything. Of course I am calling it Discussion Topics because that is the entire point of the query… to bring up the items I flagged for discussion. But that doesn’t have anything to do with the parent of the topics I flagged.

EDIT: Oh I see what is happening. My screenshot shows the result of the query… that’s why it says “Discussion Topics” in there. That’s the query title. The page that the result comes from is “testing.”

Regardless, this version seems to work! (with one exception)

My original query only showed opened tasks, but your version doesn’t clear them when they are checked. How do I incorporate this into your version? (task ?b #{“NOW” “LATER” “TODO” “DOING”})

So based on your statement, there is no way to hide the parent bullet shown in the results?

Now that it works. can you help me understand how?

I would love to understand exactly what each where statement is doing so I can start to learn this.

For instance I went here: https://docs.logseq.com/#/page/advanced%20queries to look for a definition of what a “marker” or “refs” represents, but they are not defined there. I do see them used in examples so I am trying to extrapolate what they mean.

Do refs = tags? so then does [?discuss :block/name “discuss”] combined with [?b :block/refs ?discuss] basically mean “if #discuss is present”?

Does marker = task item? If so why does my original code use “task”?

Is this stuff clearly defined somewhere that you can point me to?

Appreciate the help! Sorry to be a bother, I just want to learn how to be self-sufficient vs having to have someone write queries for me much longer. lol

  • I have updated the query to filter the markers.
  • For advanced queries:
    • Understand the difference between Basic and Advanced queries
    • Check the resources
      • Don’t expect any exhaustive documentation in a single place.
    • Apply tones of patience
      • It will take whole weeks to become self-sufficient.
    • Search the forums
      • There is much material gathered about everything.
    • Keep making questions
      • Others can learn from them.
      • Try being specific, not asking about everything at once.
1 Like

While simple query statements do work in advanced queries, I advice against that route.

  1. it can cause problems with understanding and learning as you saw yourself
  2. in the backend one gets converted to the other anyway

This is possible by adding :breadcrumb-show? false below the :inputs line.

For further learning can check the resources I have listed here:

As well as the resources link provided by mentaloid.
Unfortunately documentation is scattered, but not non-existent.

And for reference on difficulty, it took me ~3 months to become somewhat proficient in this language. So take your time.

May also want to check this topic:

I have some comments explaining each line in the first post.

Thanks a bunch. I have already found the references you and @mentaloid have provided to be very valuable.

1 Like