Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from mwmitchell/master

First stab at providing the capability of creating multiple, embedded core instances using a single core-container instance.
  • Loading branch information...
commit 8d63f515d5c77ac6199e76cc733c187210a6cc2c 2 parents 578f156 + 18d0f96
Matt Lehman authored
Showing with 27 additions and 14 deletions.
  1. +15 −6 src/solrclj/servers.clj
  2. +12 −8 test/solrclj_test.clj
21 src/solrclj/servers.clj
View
@@ -2,7 +2,7 @@
^{:doc "A clojure library for Apache Solr."
:author "Matt Lehman"}
(:import [java.io File]
- [org.apache.solr.client.solrj.impl CommonsHttpSolrServer]))
+ [org.apache.solr.client.solrj.impl CommonsHttpSolrServer]))
(defmulti create-solr-server :type)
@@ -21,21 +21,30 @@
"Constructs an EmbeddedSolrServer"
[container core]
(construct-via-reflection "org.apache.solr.client.solrj.embedded.EmbeddedSolrServer"
- container core))
+ container core))
(defn core-container
"Constructs an CoreContainer"
[dir config-file]
(construct-via-reflection "org.apache.solr.core.CoreContainer"
- dir config-file))
+ dir config-file))
(defmethod create-solr-server :default [config]
(let [config (merge default-embedded-config config)
- {:keys [dir solr-config core]} config
- solr-config-file (File. (File. dir) solr-config)
- container (core-container dir solr-config-file)]
+ {:keys [dir solr-config core]} config
+ solr-config-file (File. (File. dir) solr-config)
+ container (core-container dir solr-config-file)]
(embedded-solr-server container core)))
+(defmethod create-solr-server :embedded-multi [config]
+ (let [config (merge default-embedded-config config)
+ container (core-container (:dir config) (File. (File. (:dir config)) (:solr-config config)))
+ core-names (map #(.getName %) (.getCores container))]
+ (reduce
+ #(merge %1 {(keyword %2) (embedded-solr-server container %2)})
+ {}
+ core-names)))
+
(def default-http-config
{:type :http
:host "127.0.0.1"
20 test/solrclj_test.clj
View
@@ -1,27 +1,31 @@
(ns solrclj-test
(:use [solrclj.data]
- [solrclj.test-helpers])
+ [solrclj.test-helpers])
(:use [solrclj] :reload-all)
(:use [clojure.test])
(:import [org.apache.solr.client.solrj.embedded EmbeddedSolrServer]
- [org.apache.solr.client.solrj.impl CommonsHttpSolrServer]
- [org.apache.solr.client.solrj.response QueryResponse]))
+ [org.apache.solr.client.solrj.impl CommonsHttpSolrServer]
+ [org.apache.solr.client.solrj.response QueryResponse]))
(deftest test-solr-server
(testing "Construct an EmbeddedServer"
(is (instance? EmbeddedSolrServer (solr-server test-embedded-books-conf))))
(testing "Construct a CommonsHttpSolrServer."
- (is (instance? CommonsHttpSolrServer (solr-server test-http-conf)))))
+ (is (instance? CommonsHttpSolrServer (solr-server test-http-conf))))
+ (testing "Construct a set of EmbeddedServer instances using a single core-container"
+ (let [cores (solr-server {:type :embedded-multi :dir "test-solr"})]
+ (is (map? cores))
+ (every? #(is (instance? EmbeddedSolrServer %)) (vals cores)))))
(deftest test-ping
(let [s (solr-server test-http-books-conf)
- r (ping s)]
+ r (ping s)]
(is (= "OK" (:status r)))))
(deftest test-add
(testing "Add documents to Solr"
(let [s (solr-server test-embedded-books-conf)
- r (apply add s top-selling-books)]
+ r (apply add s top-selling-books)]
(commit s)
(is (= 0 (get-in r [:responseHeader :status])))
(is (= 15 (get-in (query s "*:*") [:response :numFound])))
@@ -46,9 +50,9 @@
(is (= 10 (get-in (query s "*:*" :fq "language:en") [:response :numFound])))
(is (= 2 (get-in (query s "*:*" :fq "published:[2000 TO *]") [:response :numFound])))
(is (= 7 (get-in (query s "*:*" :fq ["language:en"
- "published:[1900 TO *]"]) [:response :numFound])))
+ "published:[1900 TO *]"]) [:response :numFound])))
(is (= 1 (get-in (query s "*:*" :fq ["language:zh"
- "published:[1900 TO *]"]) [:response :numFound]))))))
+ "published:[1900 TO *]"]) [:response :numFound]))))))
(deftest test-response-contains-metadata
(testing "Response metadata"
Please sign in to comment.
Something went wrong with that request. Please try again.