This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-30
Channels
- # asami (4)
- # babashka (3)
- # beginners (21)
- # biff (22)
- # cljs-dev (6)
- # clojure (11)
- # clojure-europe (3)
- # clojure-norway (35)
- # clojure-spain (4)
- # clojurescript (14)
- # datalevin (2)
- # emacs (12)
- # exercism (2)
- # fulcro (10)
- # honeysql (4)
- # humbleui (3)
- # hyperfiddle (49)
- # instaparse (1)
- # introduce-yourself (1)
- # missionary (1)
- # off-topic (109)
- # pathom (2)
- # practicalli (21)
- # random (2)
- # rdf (2)
- # releases (2)
- # scittle (3)
- # specter (2)
Hi folks, I've been playing around with Datalevin's fulltext search and I found this:
(require '[datalevin.core :as d])
(let [db (-> (d/empty-db "/tmp/mydb"
{:text {:db/valueType :db.type/string
:db/fulltext true}})
(d/db-with
[{:db/id 1 :text "assoc!"}
{:db/id 2 :text "assoc"}
{:db/id 3 :text "assoc-in"}
{:db/id 4 :text "assoc-dom"}
{:db/id 5 :text "assoc-meta"}
{:db/id 6 :text "associative?"}]))]
(d/q '[:find ?e ?a ?v
:in $ ?q
:where [(fulltext $ ?q) [[?e ?a ?v]]]]
db
"assoc"))
;=> #{[1 :text "assoc!"] [2 :text "assoc"]}
Is possible to tweak the data/query/index to return all the assocs?✅ 2
I was reading the search doc and well I just understood the hole idea of fulltext search wrong, I could just use regex for this, sorry about that. For reference:
(let [db (-> (d/empty-db "/tmp/mydb"
{:text {:db/valueType :db.type/string}})
(d/db-with
[{:db/id 1 :text "assoc!"}
{:db/id 2 :text "assoc"}
{:db/id 3 :text "assoc-in"}
{:db/id 4 :text "assoc-dom"}
{:db/id 5 :text "assoc-meta"}
{:db/id 6 :text "associative?"}]))]
(d/q '[:find (pull ?e [*])
:in $ ?q
:where
[(str ".*" ?q ".*") ?pattern]
[(re-pattern ?pattern) ?regex]
[(re-matches ?regex ?name)]
[?e :text ?name]]
db
"assoc"))