[2.x] How Filter Query Results Based On Nested Vector Values?

A follow up to this, I have found a work around.

Instead of using a set (i.e. #{:a :b :c}), a map which maps to true values can be used (i.e. {:a true, :b true, :c true}.

The data model would look like:

{:xt/id 0
 :name "Some Store"
 :inventory
 [{:display "Cool shirt"
   :price 10.99
   :tags {:cool true, :shirt true, :trending true}}]}

There resulting query to find the “trending” tag would be:

(xt/q n
      '{:find   [display price store-id]
         :where [($ :stores [{:xt/id store-id :inventory [item ...]}])
                 [(. item :display) display]
                 [(. item :price) price]
                 [(.. item :tags :trending) trending?]
                 [(true? trending?)]]})
1 Like