Fork me on GitHub
#datomic
<
2017-07-08
>
joelsanchez17:07:28

does the fulltext function need :db/fulltext true attributes?

joelsanchez17:07:38

(because i can't seem to make it work)

joelsanchez18:07:25

nevermind, seems to be the case 🙂

Ethan Miller19:07:31

I'm trying to set up a tagging systems in my db, I have added two attrs to handle this:

{:db/ident            :metadata/tags
  :db/valueType        :db.type/ref
  :db/cardinality      :db.cardinality/many
  :db/isComponent      true}
 {:db/ident            :metadata/tag
  :db/valueType        :db.type/keyword
  :db/cardinality      :db.cardinality/one
  :db/index            true}
This works more or less in terms of assigning tags, but how I am encountering some problems in filtering for tags. I think when doing this I assumed that I'd be able to reference the tags the way one would idents, as a keyword, e.g. :tag1. But it's proving a bit more challenging. My first approach has been to use a query filter expression, something like this:
'[:find (pull ?doc [*])
        :in $ ?tags
        :where [?doc :arb/metadata ?meta]
               [?doc :metadata/tags ?tagset]
               [(every? (set ?tags) ?tagset)]]
where :tags is a supplied list of tag keywords, e.g. [:tag1 :tag2 ...]`. But the result of the pull doesn't quite work here because for each tag the pull returns a map including the :db/id as well as the tag e.g.:
[#:arb{:metadata
        [{:db/id 17592186045497,
          :metadata/tags
          [{:db/id 17592186045498, :metadata/tag :tag1}
           {:db/id 17592186045499, :metadata/tag :tag2}],
I thought that I could still work with this by mapping over the ?tagset to extract just the tag keywords, but inside the map expression '?tagset` ends up being out of scope. So I'm a bit stumped about how I should approach this problem, which I feel must be somewhat common... Any tips?

val_waeselynck19:07:41

@ezmiller77 I don't think the :where part of the query does what you think it does. Regarding the pull result, I don't think there's anything you can do except post-process it - pull just can't give you the data in the shape you want

Ethan Miller20:07:40

actually, i think these transformation functions, or even just a custom predicate function, might be the answer: http://www.learndatalogtoday.org/chapter/6

Ethan Miller21:07:31

Nah that won't work either since all that's available at the time of the query is the eid of the value of :metadata/tags. So post-processing it is maybe. Shame.

val_waeselynck21:07:47

@ezmiller77 it's not too hard to implement your own version of pull on top of entities, if you're not too worried about performance