Fork me on GitHub
#xtdb
<
2019-06-18
>
denik14:06:17

having trouble with quoting and function calls inside a query. how could I make this work?

(q '{:find  [?e ?s ?r]
     :where [[?e :snippet ?s]
             [?e :result ?r]
             [(clojure.string/includes? ?s ?search-string) ?s-match]
             [(clojure.string/includes? ?r ?search-string) ?r-match]
             [(or ?s-match ?r-match) ?match]]
     :args  [{:?search-string "range"}]})

denik15:06:18

solved it with

(defn some-strings-include? [q & strings]
  (boolean (some #(str/includes? % q) strings)))

(defn crux-search [q-str]
 (q {:find  '[?e ?s ?r ]
     :where '[[?e :snippet ?s]
              [?e :result ?r]
              [(some-strings-include? ?search-string ?s ?r) ?match]]
     :args  [{:?search-string q-str}]}))

refset00:06:03

Hey @U050CJFRU sorry I wasn't responsive for this. I'm glad you figured it out okay though! Which example did you find most helpful for working it out?

denik00:06:39

thanks @U899JBRPF this from the docs helped > Note that many of these not yet supported query features can be achieved via simple function calls since you can currently fully qualify any function that is loaded. In future, limitations on available functions may be introduced to enforce security restrictions for remote query execution.

refset12:06:54

Cool, good to know! I will see if I can make this more prominent somehow.

denik15:06:32

Is there a way to query tx-time or valid-time? This doesn't work:

{:find  '[?e ?s ?r ?t]
 :where '[[?e :snippet ?s]
          [?e :result ?r]
          [?e :crux.db/valid-time ?t]   ; <------------
          [(some-strings-include? ?search-string ?s ?r) ?match]]
 :args  [{:?search-string "test"}]}

refset00:06:37

Queries can't access this information about the db context, i.e the valid time and transaction time coordinate used to generate the context

refset00:06:40

I don't see how you could incorporate transaction time into your documents / queries, however you can certainly include additional timestamp keys in your documents that match the valid time

refset00:06:29

These are then just regular attributes (and could support standard range queries), but you would probably want to be careful to keep them synchronised with valid time coordinates somehow as the documents get re-inserted

denik00:06:44

https://clojurians.slack.com/archives/CG3AM2F7V/p1560902860090500?thread_ts=1560871592.089400&amp;cid=CG3AM2F7V that's what I'm doing but it feels superfluous. is this a technical limitation or a design decision. if its the latter, see question above 🙂