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]))
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
(ns auto-ap.ssr.search
|
||||
(:require
|
||||
[auto-ap.graphql.utils :refer [can-see-client?]]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr.utils :refer [html-response]]
|
||||
[auto-ap.time :as atime]
|
||||
[clj-http.client :as client]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.solr :as solr]
|
||||
[com.brunobonacci.mulog :as mu]))
|
||||
|
||||
(defn try-cleanse-date [d]
|
||||
@@ -55,7 +53,7 @@
|
||||
(into []
|
||||
(filter (fn [d]
|
||||
(can-see-client? id (first (:client_id d)))))
|
||||
(solr/query (q->solr-q q))))
|
||||
(solr/query solr/impl (q->solr-q q))))
|
||||
|
||||
|
||||
(defn search-results* [q id]
|
||||
|
||||
@@ -573,7 +573,7 @@
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
(flush)
|
||||
(solr/index-documents batch))
|
||||
(solr/index-documents solr/impl batch))
|
||||
|
||||
(doseq [batch (->> (dc/qseq {:query '[:find ?i
|
||||
:in $
|
||||
@@ -584,7 +584,7 @@
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
(flush)
|
||||
(solr/index-documents batch))
|
||||
(solr/index-documents solr/impl batch))
|
||||
|
||||
(doseq [batch (->> (dc/qseq {:query '[:find ?i
|
||||
:in $
|
||||
@@ -595,7 +595,7 @@
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
(flush)
|
||||
(solr/index-documents batch))
|
||||
(solr/index-documents solr/impl batch))
|
||||
(doseq [batch (->> (dc/qseq {:query '[:find ?i
|
||||
:in $
|
||||
:where [?i :journal-entry/date]]
|
||||
@@ -604,7 +604,7 @@
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
(flush)
|
||||
(solr/index-documents batch)))
|
||||
(solr/index-documents solr/impl batch)))
|
||||
|
||||
(defn setup-sales-orders []
|
||||
(doseq [n (->> (dc/qseq {:query '[:find ?s ?c :where [?s :sales-order/client ?c]] :args [(dc/db auto-ap.datomic/conn)]})
|
||||
|
||||
Reference in New Issue
Block a user