clientize.
This commit is contained in:
@@ -117,43 +117,61 @@
|
||||
"type" "payment"}))
|
||||
|
||||
|
||||
(defprotocol SolrClient
|
||||
(index-documents [this xs])
|
||||
(query [this q])
|
||||
(delete [this]))
|
||||
|
||||
(defn index-documents [xs]
|
||||
(client/post
|
||||
(str solr-uri "/solr/invoices/update?commitWithin=15000")
|
||||
{:headers {"Content-Type" "application/json"}
|
||||
:socket-timeout 30000
|
||||
:connection-timeout 30000
|
||||
:method "POST"
|
||||
:body (json/write-str (filter identity (map datomic->solr xs)))}))
|
||||
(defrecord RealSolrClient [solr-uri]
|
||||
|
||||
(defn query [q]
|
||||
(-> (client/post (str solr-uri "/solr/invoices/query")
|
||||
{:body (json/write-str {"query" q
|
||||
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})
|
||||
:socket-timeout 30000
|
||||
:connection-timeout 30000
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:as :json}
|
||||
)
|
||||
:body
|
||||
:response
|
||||
:docs))
|
||||
SolrClient
|
||||
(index-documents [this xs]
|
||||
(client/post
|
||||
(str solr-uri "/solr/invoices/update?commitWithin=15000")
|
||||
{:headers {"Content-Type" "application/json"}
|
||||
:socket-timeout 30000
|
||||
:connection-timeout 30000
|
||||
:method "POST"
|
||||
:body (json/write-str (filter identity (map datomic->solr xs)))}))
|
||||
|
||||
(defn solr-delete []
|
||||
(client/post
|
||||
(str solr-uri "/solr/invoices/update?commitWithin=1000")
|
||||
{:headers {"Content-Type" "application/json"}
|
||||
:method "POST"
|
||||
:body (json/write-str {"delete" {"query" "*:*"}})})
|
||||
)
|
||||
(query [this q]
|
||||
(-> (client/post (str solr-uri "/solr/invoices/query")
|
||||
{:body (json/write-str {"query" q
|
||||
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})
|
||||
:socket-timeout 30000
|
||||
:connection-timeout 30000
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:as :json}
|
||||
)
|
||||
:body
|
||||
:response
|
||||
:docs))
|
||||
(delete [this]
|
||||
(client/post
|
||||
(str solr-uri "/solr/invoices/update?commitWithin=1000")
|
||||
{:headers {"Content-Type" "application/json"}
|
||||
:method "POST"
|
||||
:body (json/write-str {"delete" {"query" "*:*"}})})))
|
||||
|
||||
(defrecord MockSolrClient []
|
||||
SolrClient
|
||||
(index-documents [this xs]
|
||||
nil)
|
||||
|
||||
(query [this q]
|
||||
nil)
|
||||
(delete [this]
|
||||
nil))
|
||||
|
||||
(def impl (if (= :solr (:solr-impl env))
|
||||
(->RealSolrClient (:solr-uri env))
|
||||
(->MockSolrClient )))
|
||||
|
||||
(defn touch-with-ledger [i]
|
||||
(index-documents [i
|
||||
(index-documents impl [i
|
||||
(pull-id (dc/db conn) [:journal-entry/original-entity i])]))
|
||||
|
||||
(defn touch [i]
|
||||
(index-documents [i]))
|
||||
(index-documents impl [i]))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user