You're making great progress on datalevin lately - fantastic work!
Given a connection conn open with (d/get-conn ...), is using (d/search ...) API supported?
E.g. via (d/search (-> conn deref .store .search-engines (get "datalevin")) "query") or is that not meant to be accessed like this and should be considered internal/impl.?
Of course one can search via (fulltext ...) built in, in a datalog query, Iām just curious if (d/search ...) should be used like this?
search is for standalone search engine, not for Datalog DB.
It's not meant to be accessed like that. With WAL mode, that access path wouldn't even work correctly, because there will be in-memory overlay.
OK, I thought so, thanks for confirming!
I can't seem to run a query where I have inputs for the outer query and subquery. This gives an error cannot parse binding . Is this expected?
(d/q
'[:find ?b
:in $ ?a
:where
[(q
[:find ?b
:in $ ?a
:where
[?a :attr-2 ?b]]
$ ?a)
?b]]
[[1 :attr 2]] 1)Master branch has a fix.
thx
Thanks, the reason I was trying to use a sub query was to get the max value of an attribute and use it in the outer query.
By max value, you mean the whole DB max of the attribute, or max under the query condition?
If it is the former, it's better to pass that max value in as a parameter, if it is the later, or-join or not-join
The latter, so let's say I have two attributes for an entity :category , :score and given a category I want to find the entity with the max score how can I do that in an or-join? It was my impression aggregate functions only work in a query. This is what I had
[:find ?e
[?e :category "cat"]
[(d/q [:find (max ?score) .
:in $
:where
[?ev :fire/category "cat"]
[?ev :score ?score]] $)
?score]
[?e :score ?score]]this query can be solved with not-join:
[:find ?e .
:where
[?e :category "cat"]
[?e :score ?score]
(not-join [?score]
[?other :category "cat"]
[?other :score ?other-score]
[(> ?other-score ?score)])]This reads as: "find ?e with category "cat" and score ?score, such that no other entity with the same category has a strictly greater score."
This will be much much more efficient than nested q.
I see, thank you
I was experimenting around with this and found that putting this logic inside a rule triggers a parsing error, I will try to find the root cause.
(d/q
'[:find ?e
:in $ %
:where
(entity-by-category ?e "cat")]
db
'[[(entity-by-category ?e ?cat)
[?e :category ?cat]
[?e :score ?score]
(not-join [?score ?cat]
[?other :category ?cat]
[?other :score ?other-score]
[(> ?other-score ?score)])]])file a GitHub issue if it is a bug.
In general, I would not write nested q like this. q is treated as a regular query function that is invoked for every tuple. It will have horrible performance. Subquery behavior can be had with or-join or not-join
As to this one, you can try it in datascript/datomic, if this works in them, file a GitHub issue, we can fix it.