Pages not linked from a page

Hello experts,

I’m stuck for hours now on this problem, so looking for some enlightenment …

My objective is to get all pages not listed on a MOC page named “:card_index:” (for my contacts).

I found interesting material on this community and I am able to find all the links on the page “:card_index:” with this query :

#+BEGIN_QUERY
{:query [:find ?tag
   :where
     [?b :block/page ?p]
     [?b :block/refs ?ref]
     [?ref :block/name ?tag]
     [?ref :block/journal? false]
     [?p :block/name "📇"]
 ]
 :result-transform (fn [result] (sort result))
 :view (fn [tags] [:div (for [tag (flatten tags)] [:a.tag.mr-1 {:href (str "#/page/" tag)} (str tag )] )] )
}
#+END_QUERY

The problem starts as soon as I add a “not” condition :

     (not [?p :block/name "📇"])

With the updated query, I got many pages, and sometimes pages which have a link on “:card_index:” page !!

My goal is to identify pages “forgotten” as not listed on one of my MOC pages ( I plan to get less than 5).

It seems to me I’m still far from my objective :smile:

type or paste code here

The not should not go around the name of the page, but around the references, i.e.:

(not
     [?b :block/page ?p]
     [?b :block/refs ?ref]
)

But this should be moved at the end of the :where , after ?p and ?ref have acquired their values.

1 Like

Hello mentaloid,

It works as a charm !!! Thank you so much :slight_smile:

For the record :

#+BEGIN_QUERY
{:query [:find ?tag
   :where
    [?ref :block/name ?tag]
    (not [?b :block/page ?p]
     [?b :block/refs ?ref] 
      )
     [?ref :block/journal? false]
     [?p :block/name "📇"]
 ]
 :result-transform (fn [result] (sort result))
 :view (fn [tags] [:div (for [tag (flatten tags)] [:a.tag.mr-1 {:href (str "#/page/" tag)} (str tag )] )] )
}
#+END_QUERY