Skip to content

Commit 851221d

Browse files
committed
fix: updates playground with fulltext sorted search
1 parent d8699a8 commit 851221d

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

dev/playground.clj

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,34 @@
4949
(println "bulking")
5050
(core/extract! {}))
5151

52+
(defn >> [a] (prn a) a)
53+
5254
; fulltext search with generated database
5355
(let [conn (d/get-conn "target/docs-db"
5456
datalevin/db-schemas)
5557

5658
db (d/db conn)
5759

58-
result (doall (d/q '[:find ?e ?a ?v ;(pull ?e [*])
59-
:in $ ?q
60-
:where
61-
[(fulltext $ ?q {:top 30
62-
:domains ["definition-name"]})
63-
[[?e ?a ?v]]]]
64-
db
65-
"a"))]
60+
datoms (->> (d/fulltext-datoms db
61+
"ass"
62+
{:top 30
63+
:domains ["definition-name"
64+
"namespace-name"
65+
"project-name"]})
66+
(map first)
67+
(d/pull-many db '[:definition/id
68+
:definition/name
69+
:definition/doc
70+
:namespace/id
71+
:namespace/name
72+
:namespace/doc
73+
:project/id
74+
:project/artifact
75+
:project/group]))]
6676
(d/close conn)
67-
result)
77+
datoms)
6878

69-
; fulltext raw search with generated database
79+
; fulltext raw search with generated database
7080
(let [lmdb (d/open-kv "target/docs-db")
7181
engine (d/new-search-engine lmdb {:query-analyzer (su/create-analyzer
7282
{:tokenizer (su/create-regexp-tokenizer #"[\s:/\.;,!=?\"'()\[\]{}|<>&@#^*\\~`\-]+")
@@ -121,10 +131,10 @@
121131
; tests with fulltext search
122132
(let [conn (d/get-conn "target/docs-db" datalevin/db-schemas)
123133
db (d/db conn)
124-
result (doall (d/q '[:find ?e ?name ?a ?v
134+
result (doall (d/q '[:find ?e ?name ?a ?v ?b ?d
125135
:in $ ?q
126136
:where
127-
[(fulltext $ ?q) [[?e ?a ?v]]]
137+
[(fulltext $ ?q) [[?e ?a ?v ?b ?d]]]
128138
[?e :definition/name ?name]]
129139
db
130140
"assoc"))]
@@ -135,6 +145,7 @@
135145
(let [query-analyzer (su/create-analyzer
136146
{:tokenizer (su/create-regexp-tokenizer #"[\s:/\.;,!=?\"'()\[\]{}|<>&@#^*\\~`\-]+")
137147
:token-filters [su/lower-case-token-filter]})
148+
138149
analyzer (su/create-analyzer
139150
{:tokenizer (su/create-regexp-tokenizer #"[\s:/\.;,!=?\"'()\[\]{}|<>&@#^*\\~`\-]+")
140151
:token-filters [su/lower-case-token-filter
@@ -148,29 +159,35 @@
148159
{:search-domains {"txt" {:analyzer analyzer
149160
:query-analyzer query-analyzer}}})
150161

151-
data [{:text "abs"}
162+
data [{:text "a"}
163+
{:text "abs"}
152164
{:text "assoc!"}
153165
{:text "assoc"}
154166
{:text "assoc-in"}
155167
{:text "assoc-dom"}
156168
{:text "assoc-meta"}
157-
{:text "associative?"}]
169+
{:text "associative?"}
170+
{:text "b"}
171+
{:text "ba"}
172+
{:text "bas"}]
158173

159174
_transact (d/transact! conn data)
160175

161-
result (d/q '[:find ?e ?a ?v
162-
:in $ ?q
163-
:where [(fulltext $ ?q {:domains ["txt"]
164-
:display :refs}) [[?e ?a ?v]]]]
165-
(d/db conn)
166-
"a")]
176+
result (->> (d/q '[:find ?i
177+
:in $ ?q
178+
:where
179+
[(fulltext $ ?q {:top 20}) [[?e]]]
180+
[?e :text ?i]]
181+
(d/db conn)
182+
"assoc-me")
183+
doall)]
167184

168185
(d/close conn)
169186
(util/delete-files dir)
170187

171188
result)
172189

173-
; tests with fulltext and analyzer on a raw query
190+
; tests with fulltext and analyzer on a raw query
174191
(let [query-analyzer (su/create-analyzer
175192
{:tokenizer (su/create-regexp-tokenizer #"[\s:/\.;,!=?\"'()\[\]{}|<>&@#^*\\~`\-]+")
176193
:token-filters [su/lower-case-token-filter]})
@@ -186,23 +203,23 @@
186203
:analyzer analyzer
187204
:include-text? true
188205
:domain "definition-name"})
189-
input {1 "abs"
206+
input {0 "a"
207+
1 "abs"
190208
2 "assoc!"
191209
3 "assoc"
192210
4 "assoc-in"
193211
5 "assoc-dom"
194212
6 "assoc-meta"
195-
7 "associative?"}
213+
7 "associative?"
214+
8 "b"
215+
9 "ba"
216+
10 "bas"}
196217

197218
_transact (doseq [[k v] input]
198219
(d/add-doc engine k v))
199220

200-
result (doall (d/search engine "a" {:top 20 :display :texts}))]
221+
result (doall (d/search engine "assoc-m" {:top 20 :display :texts}))]
201222

202223
(d/close-kv lmdb)
203224

204225
result))
205-
206-
207-
208-

0 commit comments

Comments
 (0)