Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to solr 8.2.0 and Clojure 1.10.1 #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(defproject com.codesignals/flux "0.6.0"
(defproject com.codesignals/flux "0.6.1"
:description "A clojure client library for Solr"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.apache.solr/solr-core "5.4.0"]
[org.apache.solr/solr-solrj "5.4.0"]]
:profiles {:dev {:dependencies [[midje "1.6.3"]
[org.slf4j/slf4j-log4j12 "1.7.7"]
[commons-logging "1.1.3"]]
:dependencies [[org.clojure/clojure "1.10.1"]
[org.apache.solr/solr-core "8.2.0"]
[org.apache.solr/solr-solrj "8.2.0"]]
:profiles {:dev {:dependencies [[midje/midje "1.9.9"]
[org.slf4j/slf4j-log4j12 "1.7.28"]
[commons-logging "1.2"]]
:resource-paths ["dev-resources"]
:plugins [[lein-midje "3.1.1"]]}})
:plugins [[lein-midje "3.2.1"]]}})
57 changes: 28 additions & 29 deletions src/flux/client.clj
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
(ns flux.client
(require [flux.update :refer [create-doc]]
[flux.query :refer [create-query]]
[flux.response :refer [->clojure]])
(import [org.apache.solr.client.solrj SolrServer]
[org.apache.solr.common SolrInputDocument]))
(:require [flux.update :refer [create-doc]]
[flux.query :refer [create-query]]
[flux.response :refer [->clojure]])
(:import (org.apache.solr.client.solrj SolrClient)))

(defn query [^SolrServer solr-server query & [options]]
(defn query [^SolrClient solr-server query & [options]]
(->clojure (.query solr-server (create-query query options))))

(defn request [^SolrServer solr-server request]
(defn request [^SolrClient solr-server request]
(->clojure (.request solr-server request)))

(defmulti add
(fn [_ input & _]
(cond
(map? input) :one
:else :default)))
(fn [_ input & _]
(cond
(map? input) :one
:else :default)))

(defmethod add :one [^SolrServer client doc & {:as opts}]
(defmethod add :one [^SolrClient client doc & {:as opts}]
(->clojure (.add client (create-doc doc))))

(defmethod add :default [^SolrServer client docs & {:as opts}]
(defmethod add :default [^SolrClient client docs & {:as opts}]
(->clojure (.add client ^java.util.Collection (map create-doc docs))))

(defn commit [^SolrServer client & {:as opts}]
(defn commit [^SolrClient client & {:as opts}]
(->clojure (.commit client)))

(letfn [(v [x]
(cond (keyword? x) (name x) :else (str x)))]
(defn delete-by-id [^SolrServer client ids & {:as opts}]
(defn delete-by-id [^SolrClient client ids & {:as opts}]
(->clojure
(let [ids (if (coll? ids) (map v ids) (v ids))]
(.deleteById ^SolrServer client ^java.util.List ids)))))
(let [ids (if (coll? ids) (map v ids) (v ids))]
(.deleteById ^SolrClient client ^java.util.List ids)))))

(defn delete-by-query [^SolrServer client q & {:as opts}]
(defn delete-by-query [^SolrClient client q & {:as opts}]
(->clojure (.deleteByQuery client q)))

(defn optimize
([^SolrServer client]
(->clojure (.optimize client)))
([^SolrServer client wait-flush wait-searcher]
(->clojure (.optimize client wait-flush wait-searcher)))
([^SolrServer client wait-flush wait-searcher max-segments]
(->clojure
(.optimize client wait-flush wait-searcher max-segments))))

(defn rollback [^SolrServer client]
([^SolrClient client]
(->clojure (.optimize client)))
([^SolrClient client wait-flush wait-searcher]
(->clojure (.optimize client wait-flush wait-searcher)))
([^SolrClient client wait-flush wait-searcher max-segments]
(->clojure
(.optimize client wait-flush wait-searcher max-segments))))

(defn rollback [^SolrClient client]
(->clojure (.rollback client)))

(defn shutdown [^SolrServer client]
(defn shutdown [^SolrClient client]
(->clojure (.shutdown client)))

(defn ping [^SolrServer client]
(defn ping [^SolrClient client]
(->clojure (.ping client)))
11 changes: 6 additions & 5 deletions src/flux/cloud.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns flux.cloud
(import [org.apache.solr.client.solrj.impl CloudSolrServer]))
(:import [org.apache.solr.client.solrj.impl CloudSolrClient$Builder]))

(defn create
([zk-hosts]
(CloudSolrServer. zk-hosts))
(-> (CloudSolrClient$Builder. zk-hosts)
(.build)))
([zk-hosts default-collection]
(let [server (CloudSolrServer. zk-hosts)]
(.setDefaultCollection server default-collection)
server)))
(let [client (create zk-hosts)]
(.setDefaultCollection client default-collection)
client)))
2 changes: 1 addition & 1 deletion src/flux/core.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns flux.core
(require [flux.client]))
(:require [flux.client]))

(def ^:dynamic *connection*)

Expand Down
13 changes: 6 additions & 7 deletions src/flux/embedded.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(ns flux.embedded
(import [java.io File]
[org.apache.solr.client.solrj.embedded EmbeddedSolrServer]
[org.apache.solr.core CoreContainer]
[java.nio.file Paths]
[java.net URI]))
(:import [java.io File]
[org.apache.solr.client.solrj.embedded EmbeddedSolrServer]
[org.apache.solr.core CoreContainer]
[java.nio.file Paths]))

(defn- str->path [str-path]
(-> str-path File. .toURI Paths/get))
Expand All @@ -22,8 +21,8 @@
(CoreContainer. solr-home))
([^String solr-home-path ^String solr-config-path]
(CoreContainer/createAndLoad
(str->path solr-home-path)
(str->path solr-config-path))))
(str->path solr-home-path)
(str->path solr-config-path))))

(defn create [^CoreContainer core-container core-name]
{:pre [(some #(% core-name) [string? keyword?])]}
Expand Down
5 changes: 3 additions & 2 deletions src/flux/http.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns flux.http
(import [org.apache.solr.client.solrj.impl HttpSolrServer]))
(:import [org.apache.solr.client.solrj.impl HttpSolrClient$Builder]))

(defn create [base-url core-name]
(HttpSolrServer. (str base-url "/" (name core-name))))
(-> (HttpSolrClient$Builder. (str base-url "/" (name core-name)))
(.build)))
32 changes: 16 additions & 16 deletions src/flux/query.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns flux.query
(import [org.apache.solr.common.params MultiMapSolrParams]
[org.apache.solr.client.solrj.request QueryRequest]
[org.apache.solr.client.solrj SolrRequest$METHOD]))
(:import [org.apache.solr.common.params MultiMapSolrParams]
[org.apache.solr.client.solrj.request QueryRequest]
[org.apache.solr.client.solrj SolrRequest$METHOD]))

(def method-map
{:get SolrRequest$METHOD/GET
{:get SolrRequest$METHOD/GET
:post SolrRequest$METHOD/POST})

(defn- format-param [p]
Expand All @@ -15,23 +15,23 @@

(defn- create-solr-params [m]
(MultiMapSolrParams.
(reduce-kv (fn [^java.util.HashMap hm k v]
(doto hm
(.put (format-param k)
(format-values v))))
(java.util.HashMap.) m)))
(reduce-kv (fn [^java.util.HashMap hm k v]
(doto hm
(.put (format-param k)
(format-values v))))
(java.util.HashMap.) m)))

(defn create-query [query options]
(create-solr-params (assoc options :q query)))

(defn create-query-request
([params]
(create-query-request nil params))
(create-query-request nil params))
([path params]
(create-query-request :get path params))
(create-query-request :get path params))
([method path params]
{:pre [(or (nil? path) (re-find #"^\/" (str path)))
(get method-map method)]}
(doto
(QueryRequest. (create-solr-params params) (get method-map method))
(.setPath path))))
{:pre [(or (nil? path) (re-find #"^\/" (str path)))
(get method-map method)]}
(doto
(QueryRequest. (create-solr-params params) (get method-map method))
(.setPath path))))
28 changes: 14 additions & 14 deletions src/flux/response.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns flux.response
(:import [org.apache.solr.client.solrj SolrResponse]
[org.apache.solr.common.util NamedList SimpleOrderedMap]
[org.apache.solr.common.util NamedList]
[org.apache.solr.common SolrDocumentList SolrDocument]
[org.apache.solr.common SolrInputDocument]
[java.util ArrayList]))
Expand All @@ -17,28 +17,28 @@

(defmethod ->clojure SolrDocumentList [^SolrDocumentList obj]
(merge
{:numFound (.getNumFound obj)
:start (.getStart obj)
:docs (mapv ->clojure (iterator-seq (.iterator obj)))}
(when-let [ms (.getMaxScore obj)]
{:maxScore ms})))
{:numFound (.getNumFound obj)
:start (.getStart obj)
:docs (mapv ->clojure (iterator-seq (.iterator obj)))}
(when-let [ms (.getMaxScore obj)]
{:maxScore ms})))

(defmethod ->clojure SolrDocument [^SolrDocument obj]
(reduce
(fn [acc f]
(assoc acc (keyword f) (->clojure (.getFieldValue obj f))))
{}
(.getFieldNames obj)))
(fn [acc f]
(assoc acc (keyword f) (->clojure (.getFieldValue obj f))))
{}
(.getFieldNames obj)))

(defmethod ->clojure SolrResponse [^SolrResponse obj]
(->clojure (.getResponse obj)))

(defmethod ->clojure SolrInputDocument [^SolrInputDocument obj]
(reduce
(fn [acc o]
(assoc acc (keyword o) (.getFieldValue obj o)))
{}
(.getFieldNames obj)))
(fn [acc o]
(assoc acc (keyword o) (.getFieldValue obj o)))
{}
(.getFieldNames obj)))

(defmethod ->clojure java.util.LinkedHashMap [obj]
(into {} (for [[k v] obj] [(keyword k) (->clojure v)])))
Expand Down
2 changes: 1 addition & 1 deletion src/flux/update.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns flux.update
(import [org.apache.solr.common SolrInputDocument]))
(:import [org.apache.solr.common SolrInputDocument]))

;; NOTE: The result of this function is a SolrInputDocument
;; which throws an exception when printed!
Expand Down