|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
(ns wanijo.public.db
|
|
|
|
|
(:require [wanijo.infrastructure.neo4j :as neo4j]))
|
|
|
|
|
(:require [wanijo.infrastructure.neo4j :as neo4j]
|
|
|
|
|
[wanijo.specs :as specs]
|
|
|
|
|
[clojure.set :refer [map-invert]]
|
|
|
|
|
[clojure.spec.alpha :as spec]))
|
|
|
|
|
|
|
|
|
|
(def schema-uuids
|
|
|
|
|
{:coc (or (System/getenv "SCHEMA_COC")
|
|
|
|
@ -191,13 +194,14 @@
|
|
|
|
|
:desc (propery-of-attribute i (:comp-desc attribute-uuids)))))
|
|
|
|
|
|
|
|
|
|
(neo4j/defquery search
|
|
|
|
|
"MATCH (i:instance)
|
|
|
|
|
"MATCH (i:instance)-[:of]->(s:schema)
|
|
|
|
|
OPTIONAL MATCH (i)<-[:of]-(p:property)
|
|
|
|
|
WITH i, p
|
|
|
|
|
WITH i, p, s
|
|
|
|
|
WHERE toLower(i.name) =~ toLower('(?s).*' + {term} + '.*')
|
|
|
|
|
OR toLower(p.name) =~ toLower('(?s).*' + {term} + '.*')
|
|
|
|
|
OR toLower(p.value) =~ toLower('(?s).*' + {term} + '.*')
|
|
|
|
|
RETURN i, p,
|
|
|
|
|
RETURN i, p, s,
|
|
|
|
|
(i)--(:instance {uuid:{coc_uuids}}) AS path,
|
|
|
|
|
CASE
|
|
|
|
|
WHEN toLower(i.name) =~ toLower('(?s).*' + {term} + '.*') THEN
|
|
|
|
|
i.name
|
|
|
|
@ -206,14 +210,48 @@
|
|
|
|
|
ELSE
|
|
|
|
|
p.value
|
|
|
|
|
END AS m")
|
|
|
|
|
(spec/def ::props
|
|
|
|
|
(spec/coll-of
|
|
|
|
|
(spec/keys :req-un [::specs/created_at
|
|
|
|
|
::specs/updated_at
|
|
|
|
|
::specs/uuid
|
|
|
|
|
::specs/value])))
|
|
|
|
|
(spec/def ::which (set (keys schema-uuids)))
|
|
|
|
|
(spec/def ::schema
|
|
|
|
|
(spec/keys :req-un [::specs/name
|
|
|
|
|
::specs/created_at
|
|
|
|
|
::specs/uuid
|
|
|
|
|
::which]))
|
|
|
|
|
(spec/def ::match (spec/and string?
|
|
|
|
|
not-empty))
|
|
|
|
|
(spec/def ::search-result-list
|
|
|
|
|
(spec/coll-of
|
|
|
|
|
(spec/keys :req-un [::specs/name
|
|
|
|
|
::specs/created_at
|
|
|
|
|
::specs/updated_at
|
|
|
|
|
::specs/uuid
|
|
|
|
|
::props
|
|
|
|
|
::match
|
|
|
|
|
::schema])))
|
|
|
|
|
(defn search! [term]
|
|
|
|
|
(->> (neo4j/exec-query! search {:term term})
|
|
|
|
|
(group-by :i)
|
|
|
|
|
(map #(assoc (key %)
|
|
|
|
|
:props (filter some?
|
|
|
|
|
(map :p (val %)))
|
|
|
|
|
:match (-> (val %) first :m)))
|
|
|
|
|
(sort-by :updated_at #(compare %2 %1))))
|
|
|
|
|
{:post [(spec/assert ::search-result-list %)]}
|
|
|
|
|
(let [results (->> (neo4j/exec-query! search {:term term
|
|
|
|
|
:coc_uuids (vals coc-instance-uuids)})
|
|
|
|
|
(group-by :i)
|
|
|
|
|
(map #(assoc (key %)
|
|
|
|
|
:props (filter some?
|
|
|
|
|
(map :p (val %)))
|
|
|
|
|
:match (-> (val %) first :m)
|
|
|
|
|
:schema (-> (val %) first :s)
|
|
|
|
|
:path (-> (val %) first :path)))
|
|
|
|
|
(sort-by :updated_at #(compare %2 %1)))]
|
|
|
|
|
(map (fn [finding]
|
|
|
|
|
(assoc-in finding
|
|
|
|
|
[:schema :which]
|
|
|
|
|
(get (map-invert schema-uuids)
|
|
|
|
|
(-> finding :schema :uuid))))
|
|
|
|
|
results)))
|
|
|
|
|
(comment
|
|
|
|
|
(search! "Builtools")
|
|
|
|
|
(search! "Arschitektur"))
|
|
|
|
|
(search! "Arschitektur")
|
|
|
|
|
(search! "Angular"))
|
|
|
|
|