From 5f04a48c2a369c698afab90198ecae5583e8098f Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Thu, 4 Aug 2016 18:50:34 -0700 Subject: [PATCH] Add explicit fts-table to source. --- src/datomish/query/source.cljc | 17 +++++++++++++++-- test/datomish/test/query.cljc | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/datomish/query/source.cljc b/src/datomish/query/source.cljc index 1e488279..00ff167b 100644 --- a/src/datomish/query/source.cljc +++ b/src/datomish/query/source.cljc @@ -35,6 +35,9 @@ (defprotocol Source (source->from [source attribute] "Returns a pair, `[table alias]` for a pattern with the provided attribute.") + (source->non-fts-from [source]) + (source->fts-from [source] + "Returns a pair, `[table alias]` for querying the source's fulltext index.") (source->constraints [source alias]) (attribute-in-source [source attribute]) (constant-in-source [source constant])) @@ -42,6 +45,7 @@ (defrecord DatomsSource [table ; Typically :datoms. + fts-table ; Typically :fulltext_values fts-view ; Typically :fulltext_datoms. columns ; e.g., [:e :a :v :tx] @@ -51,7 +55,7 @@ ;; turn, e.g., the literal 'true' into 1. attribute-transform constant-transform - + ;; `table-alias` is a function from table to alias, e.g., :datoms => :datoms1234. table-alias @@ -61,7 +65,7 @@ Source (source->from [source attribute] - (let [table + (let [table (if (and (instance? Constant attribute) ;; TODO: look in the DB schema to see if `attribute` is known to not be ;; a fulltext attribute. @@ -72,6 +76,14 @@ (:fts-view source))] [table ((:table-alias source) table)])) + (source->non-fts-from [source] + (let [table (:table source)] + [table ((:table-alias source) table)])) + + (source->fts-from [source] + (let [table (:fts-table source)] + [table ((:table-alias source) table)])) + (source->constraints [source alias] (when-let [f (:make-constraints source)] (f alias))) @@ -85,6 +97,7 @@ (defn datoms-source [db] (map->DatomsSource {:table :datoms + :fts-table :fulltext_values :fts-view :fulltext_datoms :columns [:e :a :v :tx :added] :attribute-transform transforms/attribute-transform-string diff --git a/test/datomish/test/query.cljc b/test/datomish/test/query.cljc index 2518a5a6..5db632f4 100644 --- a/test/datomish/test/query.cljc +++ b/test/datomish/test/query.cljc @@ -28,6 +28,7 @@ (defn mock-source [db] (source/map->DatomsSource {:table :datoms + :fts-table :fulltext_values :fts-view :fulltext_datoms :columns [:e :a :v :tx :added] :attribute-transform transforms/attribute-transform-string