Browse Source

DB refactor and fix issues related to tags and aliases

1. add a `page` filter.
2. keep word case for both page and block's properties
3. remove `:tag/name` from the db schema

Fixed #1031
Tienson Qin 4 years ago
parent
commit
48b6ccbdca

+ 14 - 23
src/main/frontend/components/block.cljs

@@ -949,13 +949,10 @@
     (->elem
      :span
      {:class "block-tags"}
-     (mapv (fn [{:keys [db/id tag/name]}]
-             (if (util/tag-valid? name)
-               [:a.tag.mx-1 {:key (str "tag-" id)
-                             :href (rfe/href :page {:name name})}
-                (str "#" name)]
-               [:span.warning.mx-1 {:title "Invalid tag, tags only accept alphanumeric characters, \"-\", \"_\", \"@\" and \"%\"."}
-                (str "#" name)]))
+     (mapv (fn [tag]
+             [:a.tag.mx-1 {:key (str "tag-" tag)
+                           :href (rfe/href :page {:name tag})}
+              (str "#" tag)])
            tags))))
 
 (defn build-block-part
@@ -1068,10 +1065,10 @@
           [:span.mr-1 ":"]
           (if (coll? v)
             (let [v (->> (remove string/blank? v)
-                         (filter string?))]
-              (for [v-item v]
-                [:span.mr-2
-                 (page-cp config {:page/name v-item})]))
+                         (filter string?))
+                  vals (for [v-item v]
+                         (page-cp config {:page/name v-item}))]
+              (interpose [:span ", "] vals))
             (inline-text (:block/format block) (str v)))])])))
 
 (rum/defcs timestamp-cp < rum/reactive
@@ -1688,23 +1685,17 @@
       ["Properties" m]
       [:div.properties
        (let [format (:block/format config)]
-         (for [[k v] m]
+         (for [[k v] (dissoc m :roam_alias :roam_tags)]
            (when (and (not (and (= k :macros) (empty? v))) ; empty macros
 )
              [:div.property
               [:span.font-medium.mr-1 (str (name k) ": ")]
               (if (coll? v)
-                (for [item v]
-                  (if (or (= k :tags)
-                          (= k :alias))
-                    (if (string/includes? item "[[")
-                      (inline-text format item)
-                      (let [p (-> item
-                                  (string/replace "[" "")
-                                  (string/replace "]" ""))]
-                        [:a.mr-2 {:href (rfe/href :page {:name p})}
-                         p]))
-                    (inline-text format item)))
+                (let [vals (for [item v]
+                             (if (coll? v)
+                               (page-cp config {:page/name item})
+                               (inline-text format item)))]
+                  (interpose [:span ", "] vals))
                 (inline-text format v))])))]
 
       ["Paragraph" l]

+ 1 - 1
src/main/frontend/db.cljs

@@ -37,7 +37,7 @@
  [frontend.db.model
   add-properties! block-and-children-transform blocks-count blocks-count-cache clean-export!  cloned? delete-blocks
   delete-file! delete-file-blocks! delete-file-pages! delete-file-tx delete-files delete-pages-by-files
-  filter-only-public-pages-and-blocks get-all-block-contents get-all-tagged-pages get-all-tags
+  filter-only-public-pages-and-blocks get-all-block-contents get-all-tagged-pages
   get-all-templates get-block-and-children get-block-and-children-no-cache get-block-by-uuid get-block-children
   get-block-children-ids get-block-content get-block-file get-block-immediate-children get-block-page
   get-block-page-end-pos get-block-parent get-block-parents get-block-referenced-blocks get-block-refs-count

+ 3 - 19
src/main/frontend/db/model.cljs

@@ -48,40 +48,24 @@
        react
        ffirst))))
 
-(defn get-all-tags
-  []
-  (let [repo (state/get-current-repo)]
-    (when (conn/get-conn repo)
-      (some->>
-       (react/q repo [:tags] {}
-                '[:find ?name ?h ?p
-                  :where
-                  [?t :tag/name ?name]
-                  (or
-                   [?h :block/tags ?t]
-                   [?p :page/tags ?t])])
-       react
-       (seq)))))
-
 (defn get-tag-pages
   [repo tag-name]
   (d/q '[:find ?original-name ?name
          :in $ ?tag
          :where
-         [?e :tag/name ?tag]
+         [?e :page/name ?tag]
          [?page :page/tags ?e]
          [?page :page/original-name ?original-name]
          [?page :page/name ?name]]
        (conn/get-conn repo)
-       tag-name))
+       (string/lower-case tag-name)))
 
 (defn get-all-tagged-pages
   [repo]
   (d/q '[:find ?page-name ?tag
          :where
          [?page :page/tags ?e]
-         [?e :tag/name ?tag]
-         [_ :page/name ?tag]
+         [?e :page/name ?tag]
          [?page :page/name ?page-name]]
        (conn/get-conn repo)))
 

+ 62 - 29
src/main/frontend/db/query_dsl.cljs

@@ -28,6 +28,7 @@
 ;; property (block)
 ;; todo (block)
 ;; priority (block)
+;; page
 ;; page-property (page)
 ;; page-tags (page)
 ;; all-page-tags
@@ -135,14 +136,15 @@
          page-ref? (text/page-ref? e)]
      (when (or (and page-ref?
                     (not (contains? #{'page-property 'page-tags} (:current-filter env))))
-               (contains? #{'between 'property 'todo 'priority 'sort-by} fe))
+               (contains? #{'between 'property 'todo 'priority 'sort-by 'page} fe))
        (reset! blocks? true))
      (cond
        (nil? e)
        nil
 
        page-ref?
-       (let [page-name (text/page-ref-un-brackets! e)]
+       (let [page-name (-> (text/page-ref-un-brackets! e)
+                           (string/lower-case))]
          (when (and (not (string/blank? page-name))
                     (some? (db-utils/entity repo [:page/name page-name])))
            [['?b :block/ref-pages [:page/name page-name]]]))
@@ -209,8 +211,8 @@
              (when (and start end)
                (let [[start end] (sort [start end])
                      sym '?v]
-                 [['?b :block/properties '?p]
-                  [(list 'get '?p k) sym]
+                 [['?b :block/properties '?prop]
+                  [(list 'get '?prop k) sym]
                   [(list '>= sym start)]
                   [(list '< sym end)]])))))
 
@@ -219,8 +221,8 @@
        (let [v (some-> (name (nth e 2))
                        (text/page-ref-un-brackets!))
              sym '?v]
-         [['?b :block/properties '?p]
-          [(list 'get '?p (name (nth e 1))) sym]
+         [['?b :block/properties '?prop]
+          [(list 'get '?prop (name (nth e 1))) sym]
           (list
            'or
            [(list '= sym v)]
@@ -228,8 +230,8 @@
 
        (and (= 'property fe)
             (= 2 (count e)))
-       [['?b :block/properties '?p]
-        [(list 'get '?p (name (nth e 1)))]]
+       [['?b :block/properties '?prop]
+        [(list 'get '?prop (name (nth e 1)))]]
 
        (= 'todo fe)
        (let [markers (if (coll? (first (rest e)))
@@ -267,6 +269,10 @@
                                                   comp))))
              nil)))
 
+       (= 'page fe)
+       (let [page-name (string/lower-case (first (rest e)))]
+         [['?b :block/page [:page/name page-name]]])
+
        (= 'page-property fe)
        (let [[k v] (rest e)]
          (if v
@@ -283,18 +289,20 @@
             [(list 'get '?prop (keyword (nth e 1)))]]))
 
        (= 'page-tags fe)
-       (let [tags (if (coll? (first (rest e)))
-                    (first (rest e))
-                    (rest e))]
-         (when (seq tags)
-           (let [tags (set (map (comp text/page-ref-un-brackets! name) tags))]
-             [['?p :page/tags '?t]
-              ['?t :tag/name '?tag]
-              [(list 'contains? tags '?tag)]])))
+       (do
+         (let [tags (if (coll? (first (rest e)))
+                      (first (rest e))
+                      (rest e))
+               tags (map (comp string/lower-case name) tags)]
+           (when (seq tags)
+             (let [tags (set (map (comp text/page-ref-un-brackets! string/lower-case name) tags))]
+               [['?p :page/tags '?t]
+                ['?t :page/name '?tag]
+                [(list 'contains? tags '?tag)]]))))
 
        (= 'all-page-tags fe)
-       [['?t :tag/name '?tag]
-        ['?p :page/name '?tag]]
+       [['?page :page/tags '?t]
+        ['?t :page/name '?p]]
 
        :else
        nil))))
@@ -315,6 +323,36 @@
                                                  (string/join " ")
                                                  (util/format "(between %s)"))))))
 
+(defn- add-bindings!
+  [q]
+  (let [b? (atom false)
+        p? (atom false)
+        not? (atom false)]
+    (walk/postwalk (fn [f]
+                     (cond
+                       (= 'not f)
+                       (reset! not? true)
+                       (= '?b f)
+                       (reset! b? true)
+                       (= '?p f)
+                       (reset! p? true)
+                       :else
+                       f)) q)
+    (if @not?
+      (cond
+        (and @b? @p?)
+        (concat [['?b :block/uuid] ['?p :page/name] ['?b :block/page '?p]] q)
+
+        @b?
+        (concat [['?b :block/uuid]] q)
+
+        @p?
+        (concat [['?p :page/name]] q)
+
+        :else
+        q)
+      q)))
+
 (defn parse
   [repo s]
   (when (and (string? s)
@@ -332,18 +370,13 @@
               result (when (seq result)
                        (let [key (if (coll? (first result))
                                    (keyword (ffirst result))
-                                   (keyword (first result)))]
-                         (case key
-                           :and
-                           (rest result)
-
-                           :not
-                           (cons ['?b :block/uuid] result)
-
-                           :or
-                           result
+                                   (keyword (first result)))
+                             result (case key
+                                      :and
+                                      (rest result)
 
-                           result)))]
+                                      result)]
+                         (add-bindings! result)))]
           {:query result
            :sort-by @sort-by
            :blocks? (boolean @blocks?)})

+ 1 - 7
src/main/frontend/db/react.cljs

@@ -165,7 +165,6 @@
   []
   (let [match (:route-match @state/state)
         route-name (get-in match [:data :name])
-        tag? (= route-name :tag)
         page (case route-name
                :page
                (get-in match [:path-params :name])
@@ -173,15 +172,10 @@
                :file
                (get-in match [:path-params :path])
 
-               :tag
-               (get-in match [:path-params :name])
-
                (date/journal-name))]
     (when page
       (let [page-name (util/url-decode (string/lower-case page))]
-        (db-utils/entity (if tag?
-                           [:tag/name page-name]
-                           [:page/name page-name]))))))
+        (db-utils/entity [:page/name page-name])))))
 
 (defn get-current-priority
   []

+ 1 - 7
src/main/frontend/db_schema.cljs

@@ -76,9 +76,6 @@
    :block/marker {}
    :block/priority {}
    :block/level {}
-   :block/tags {:db/valueType   :db.type/ref
-                :db/cardinality :db.cardinality/many
-                :db/isComponent true}
    ;; :start-pos :end-pos
    :block/meta {}
    :block/properties {}
@@ -92,7 +89,4 @@
    :block/scheduled-ast {}
    :block/deadline {}
    :block/deadline-ast {}
-   :block/repeated? {}
-
-   ;; For pages
-   :tag/name       {:db/unique :db.unique/identity}})
+   :block/repeated? {}})

+ 2 - 11
src/main/frontend/format/block.cljs

@@ -194,8 +194,7 @@
 
 (defn with-page-refs
   [{:keys [title body tags] :as block}]
-  (let [tags (mapv :tag/name (util/->tags (map :tag/name tags)))
-        ref-pages (atom tags)]
+  (let [ref-pages (atom tags)]
     (walk/postwalk
      (fn [form]
        (when-let [page (get-page-reference form)]
@@ -254,12 +253,6 @@
          (block-keywordize (util/remove-nils block)))
        blocks))
 
-(defn collect-block-tags
-  [{:keys [title body tags] :as block}]
-  (cond-> block
-    (seq tags)
-    (assoc :tags (util/->tags tags))))
-
 (defn extract-blocks
   [blocks last-pos encoded-content]
   (let [blocks
@@ -319,7 +312,6 @@
                       block (if (seq timestamps)
                               (merge block (timestamps->scheduled-and-deadline timestamps))
                               block)
-                      block (collect-block-tags block)
                       block (with-page-refs block)
                       block (with-block-refs block)
                       block (update-src-pos-meta! block)
@@ -382,8 +374,7 @@
            blocks (doall
                    (map-indexed
                     (fn [idx {:block/keys [ref-pages ref-blocks meta] :as block}]
-                      (let [block (collect-block-tags block)
-                            block (merge
+                      (let [block (merge
                                    block
                                    {:block/meta meta
                                     :block/marker (get block :block/marker "nil")

+ 19 - 11
src/main/frontend/format/mldoc.cljs

@@ -66,6 +66,17 @@
         (recur (rest ast)))
       nil)))
 
+(defn- ->vec
+  [s]
+  (if (string? s) [s] s))
+
+(defn- ->vec-concat
+  [& coll]
+  (->> (map ->vec coll)
+       (remove nil?)
+       (apply concat)
+       (distinct)))
+
 (defn collect-page-properties
   [ast]
   (if (seq ast)
@@ -94,26 +105,22 @@
                    {})
           properties (->> (remove (fn [x] (= :macro (first x))) properties)
                           (into {}))
-          properties (if (:roam_alias properties)
-                       (assoc properties :alias (:roam_alias properties))
-                       properties)
           properties (if (seq properties)
                        (cond-> properties
                          (:roam_key properties)
                          (assoc :key (:roam_key properties)))
                        properties)
           definition-tags (get-tags-from-definition ast)
-          properties (if definition-tags
-                       (update properties :tags (fn [tags]
-                                                  (-> (concat tags definition-tags)
-                                                      distinct)))
-                       properties)
           properties (cond-> properties
                        (seq macros)
                        (assoc :macros macros))
-          properties (if (:alias properties)
-                       (update properties :alias (fn [alias] (if (string? alias) [alias] alias)))
-                       properties)
+          alias (->vec-concat (:roam_alias properties) (:alias properties))
+          tags (->vec-concat (:roam_tags properties) (:tags properties) definition-tags)
+          properties (assoc properties :tags tags :alias alias)
+          properties (-> properties
+                         (update :roam_alias ->vec)
+                         (update :roam_tags ->vec))
+          properties (medley/filter-kv (fn [k v] (not (empty? v))) properties)
           other-ast (drop-while (fn [[item _pos]] (directive? item)) original-ast)]
       (if (seq properties)
         (cons [["Properties" properties] nil] other-ast)
@@ -164,6 +171,7 @@
   (let [ast (->> (->edn content
                         (default-config format))
                  (map first))
+        properties (collect-page-properties ast)
         properties (let [properties (and (seq ast)
                                          (= "Properties" (ffirst ast))
                                          (last (first ast)))]

+ 8 - 13
src/main/frontend/handler/editor.cljs

@@ -448,14 +448,14 @@
                                            [(:page/properties (db/entity (:db/id page)))
                                             (mldoc/parse-properties value format)])
          page-tags (when-let [tags (:tags new-properties)]
-                     (util/->tags tags))
+                     (mapv (fn [tag] {:page/name (string/lower-case tag)
+                                     :page/original-name tag}) tags))
          page-alias (when-let [alias (:alias new-properties)]
-                      (let [alias (text/split-page-refs-without-brackets alias)
-                            alias (if (string? alias) [alias] alias)]
-                        (map
-                         (fn [alias]
-                           {:page/name (string/lower-case alias)})
-                         (remove #{(:page/name page)} alias))))
+                      (map
+                        (fn [alias]
+                          {:page/original-name alias
+                           :page/name (string/lower-case alias)})
+                        (remove #{(:page/name page)} alias)))
          permalink-changed? (when (and pre-block? (:permalink old-properties))
                               (not= (:permalink old-properties)
                                     (:permalink new-properties)))
@@ -559,12 +559,7 @@
                                        :page/properties new-properties}]
                                      [[:db/retract page-id :page/properties]]))
                  pages (if (seq page-tags)
-                         (let [tag-pages (map
-                                          (fn [page]
-                                            {:page/original-name page
-                                             :page/name page})
-                                          (map :tag/name page-tags))]
-                           (concat pages tag-pages))
+                         (concat pages page-tags)
                          pages)
                  pages (remove
                         (fn [page]

+ 17 - 27
src/main/frontend/handler/extract.cljs

@@ -54,11 +54,9 @@
                  (map
                   (fn [page]
                     (let [page-file? (= page (string/lower-case file))
-                          other-alias (and (:alias properties)
+                          aliases (and (:alias properties)
                                            (seq (remove #(= page %)
                                                         (:alias properties))))
-                          other-alias (distinct
-                                       (remove nil? other-alias))
                           journal-date-long (if journal?
                                               (date/journal-title->long (string/capitalize page)))
                           page-list (when-let [list-content (:list properties)]
@@ -77,40 +75,32 @@
                         (seq properties)
                         (assoc :page/properties properties)
 
-                        other-alias
+                        aliases
                         (assoc :page/alias
                                (map
                                 (fn [alias]
-                                  (let [alias (string/lower-case alias)
-                                        aliases (->>
-                                                 (distinct
-                                                  (conj
-                                                   (remove #{alias} other-alias)
-                                                   page))
-                                                 (remove nil?))
+                                  (let [page-name (string/lower-case alias)
+                                        aliases (distinct
+                                                 (conj
+                                                  (remove #{alias} aliases)
+                                                  page))
                                         aliases (if (seq aliases)
                                                   (map
                                                    (fn [alias]
                                                      {:page/name alias})
                                                    aliases))]
                                     (if (seq aliases)
-                                      {:page/name alias
+                                      {:page/name page-name
                                        :page/alias aliases}
-                                      {:page/name alias})))
-                                other-alias))
+                                      {:page/name page-name})))
+                                 aliases))
 
-                        (or (:tags properties) (:roam_tags properties))
-                        (assoc :page/tags (let [tags (:tags properties)
-                                                roam-tags (:roam_tags properties)
-                                                tags (if (string? tags)
-                                                       (string/split tags #",")
-                                                       tags)
-                                                tags (->> (concat tags roam-tags)
-                                                          (remove nil?)
-                                                          (distinct))
-                                                tags (util/->tags tags)]
-                                            (swap! ref-tags set/union (set (map :tag/name tags)))
-                                            tags)))))
+                        (:tags properties)
+                        (assoc :page/tags (let [tags (:tags properties)]
+                                            (swap! ref-tags set/union (set tags))
+                                            (map (fn [tag] {:page/name (string/lower-case tag)
+                                                           :page/original-name tag})
+                                              tags))))))
                   (->> (map first pages)
                        (remove nil?))))
           pages (concat
@@ -118,7 +108,7 @@
                  (map
                   (fn [page]
                     {:page/original-name page
-                     :page/name page})
+                     :page/name (string/lower-case page)})
                   @ref-tags)
                  (map
                   (fn [page]

+ 1 - 2
src/main/frontend/handler/graph.cljs

@@ -104,8 +104,7 @@
       (let [page (string/lower-case page)
             page-entity (db/entity [:page/name page])
             original-page-name (:page/original-name page-entity)
-            tags (->> (:page/tags page-entity)
-                      (map :tag/name))
+            tags (:tags (:page/properties page-entity))
             tags (remove #(= page %) tags)
             ref-pages (db/get-page-referenced-pages repo page)
             mentioned-pages (db/get-pages-that-mentioned-page repo page)

+ 4 - 6
src/main/frontend/text.cljs

@@ -18,10 +18,9 @@
 (defn page-ref-un-brackets!
   [s]
   (when (string? s)
-    (let [s (if (page-ref? s)
-              (subs s 2 (- (count s) 2))
-              s)]
-      (string/lower-case s))))
+    (if (page-ref? s)
+      (subs s 2 (- (count s) 2))
+      s)))
 
 ;; E.g "Foo Bar \"Bar Baz\""
 (defn- sep-by-comma-or-quote
@@ -30,7 +29,6 @@
     (some->>
      (string/split s #"[\"|\,|,]{1}")
      (remove string/blank?)
-     (map string/lower-case)
      (map string/trim))))
 
 (defn split-page-refs-without-brackets
@@ -185,7 +183,7 @@
                   (let [[k v] (util/split-first ":" (subs line 1))]
                     (when (and k v)
                       (let [k (string/trim (string/lower-case k))
-                            v (string/trim (string/lower-case v))]
+                            v (string/trim v)]
                         (when-not (contains? #{"properties" "end"} k)
                           [k v])))))))
          (into {}))))

+ 0 - 21
src/main/frontend/util.cljs

@@ -827,27 +827,6 @@
 (defn pp-str [x]
   (with-out-str (pprint x)))
 
-(defn ->tags
-  [tags]
-  (->> (map (fn [tag]
-              (let [tag (-> (string/trim tag)
-                            (string/lower-case)
-                            (string/replace #"\s+" "-")
-                            (string/replace #"#" "")
-                            (string/replace "[" "")
-                            (string/replace "]" ""))]
-                (if (tag-valid? tag)
-                  {:db/id tag
-                   :tag/name tag})))
-            (remove nil? tags))
-       (remove nil?)
-       vec))
-
-(defn ->page-tags
-  [s]
-  (let [tags (string/split s #",")]
-    (->tags tags)))
-
 (defn hiccup-keywordize
   [hiccup]
   (walk/postwalk

+ 25 - 25
src/test/frontend/db/query_dsl_test.cljs

@@ -100,8 +100,9 @@ parent: child page 2
 (defn- q
   [s]
   (db/clear-query-state!)
-  (let [parse-result (parse s)]
-    {:query (:query parse-result)
+  (let [parse-result (parse s)
+        query (:query parse-result)]
+    {:query query
      :result (dsl/query test-db s)}))
 
 (defn q-count
@@ -144,32 +145,32 @@ parent: child page 2
   (testing "Block properties query"
     (are [x y] (= (q-count x) y)
       "(property prop_a val_a)"
-      {:query '[[?b :block/properties ?p]
-                [(get ?p "prop_a") ?v]
+      {:query '[[?b :block/properties ?prop]
+                [(get ?prop "prop_a") ?v]
                 (or
                  [(= ?v "val_a")]
                  [(contains? ?v "val_a")])]
        :count 2}
 
       "(property prop_b val_b)"
-      {:query '[[?b :block/properties ?p]
-                [(get ?p "prop_b") ?v]
+      {:query '[[?b :block/properties ?prop]
+                [(get ?prop "prop_b") ?v]
                 (or
                  [(= ?v "val_b")]
                  [(contains? ?v "val_b")])]
        :count 1}
 
       "(and (property prop_b val_b))"
-      {:query '[[?b :block/properties ?p]
-                [(get ?p "prop_b") ?v]
+      {:query '[[?b :block/properties ?prop]
+                [(get ?prop "prop_b") ?v]
                 (or
                  [(= ?v "val_b")]
                  [(contains? ?v "val_b")])]
        :count 1}
 
       "(and (property prop_c \"page c\"))"
-      {:query '[[?b :block/properties ?p]
-                [(get ?p "prop_c") ?v]
+      {:query '[[?b :block/properties ?prop]
+                [(get ?prop "prop_c") ?v]
                 (or
                  [(= ?v "page c")]
                  [(contains? ?v "page c")])]
@@ -177,19 +178,19 @@ parent: child page 2
 
       ;; TODO: optimize
       "(and (property prop_c \"page c\") (property prop_c \"page b\"))"
-      {:query '([?b :block/properties ?p]
-                [(get ?p "prop_c") ?v]
+      {:query '([?b :block/properties ?prop]
+                [(get ?prop "prop_c") ?v]
                 (or [(= ?v "page c")] [(contains? ?v "page c")])
                 (or [(= ?v "page b")] [(contains? ?v "page b")]))
        :count 1}
 
       "(or (property prop_c \"page c\") (property prop_b val_b))"
       {:query '(or
-                (and [?b :block/properties ?p]
-                     [(get ?p "prop_c") ?v]
+                (and [?b :block/properties ?prop]
+                     [(get ?prop "prop_c") ?v]
                      (or [(= ?v "page c")] [(contains? ?v "page c")]))
-                (and [?b :block/properties ?p]
-                     [(get ?p "prop_b") ?v]
+                (and [?b :block/properties ?prop]
+                     [(get ?prop "prop_b") ?v]
                      (or [(= ?v "val_b")] [(contains? ?v "val_b")])))
        :count 2}))
 
@@ -250,39 +251,39 @@ parent: child page 2
   (testing "all-page-tags queries"
     (are [x y] (= (q-count x) y)
       "(all-page-tags)"
-      {:query '[[?t :tag/name ?tag]
-                [?p :page/name ?tag]]
+      {:query '[[?page :page/tags ?t]
+                [?t :page/name ?p]]
        :count 3}))
 
   (testing "page-tags queries"
     (are [x y] (= (q-count x) y)
       "(page-tags [[page-tag-1]])"
       {:query '[[?p :page/tags ?t]
-                [?t :tag/name ?tag]
+                [?t :page/name ?tag]
                 [(contains? #{"page-tag-1"} ?tag)]]
        :count 1}
 
       "(page-tags page-tag-2)"
       {:query '[[?p :page/tags ?t]
-                [?t :tag/name ?tag]
+                [?t :page/name ?tag]
                 [(contains? #{"page-tag-2"} ?tag)]]
        :count 2}
 
       "(page-tags page-tag-1 page-tag-2)"
       {:query '[[?p :page/tags ?t]
-                [?t :tag/name ?tag]
+                [?t :page/name ?tag]
                 [(contains? #{"page-tag-1" "page-tag-2"} ?tag)]]
        :count 2}
 
       "(page-tags page-TAG-1 page-tag-2)"
       {:query '[[?p :page/tags ?t]
-                [?t :tag/name ?tag]
+                [?t :page/name ?tag]
                 [(contains? #{"page-tag-1" "page-tag-2"} ?tag)]]
        :count 2}
 
       "(page-tags [page-tag-1 page-tag-2])"
       {:query '[[?p :page/tags ?t]
-                [?t :tag/name ?tag]
+                [?t :page/name ?tag]
                 [(contains? #{"page-tag-1" "page-tag-2"} ?tag)]]
        :count 2}))
 
@@ -348,8 +349,7 @@ parent: child page 2
     (are [x y] (= (q-count x) y)
       "(not [[page 1]])"
       {:query '([?b :block/uuid]
-                (not
-                 [?b :block/ref-pages [:page/name "page 1"]]))
+                (not [?b :block/ref-pages [:page/name "page 1"]]))
        :count 8}))
 
   (testing "Between query"