Skip to content
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
6 changes: 5 additions & 1 deletion src/flux/update.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
;; which throws an exception when printed!
(defn create-doc ^SolrInputDocument [document-map]
(reduce-kv (fn [^SolrInputDocument doc k v]
(if (map? v)
(cond
(= k :_childDocuments_)
(doto doc (.addChildDocuments (map create-doc v)))
(map? v)
(let [m (doto (java.util.HashMap.)
(.put (name (key (first v))) (val (first v))))]
(doto doc (.addField (name k) m))
doc)
:else
(doto doc (.addField (name k) v))))
(SolrInputDocument.) document-map))
14 changes: 13 additions & 1 deletion test/flux/unit/update.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
(ns flux.unit.update
(:require [flux.update :refer :all]
[midje.sweet :refer :all]))
[midje.sweet :refer :all])
(:import [org.apache.solr.common SolrInputDocument]))

(fact "create-doc"
(class (create-doc {:id 1})) => org.apache.solr.common.SolrInputDocument)

(fact "create-doc-with-children"
(let [doc { :id 1
:_childDocuments_
[{ :id "1.1"
:title "a title..."
:_childDocuments_
[{:id "1.1.1"}]}]}
solr-doc (create-doc doc)]
(.hasChildDocuments solr-doc) => true
(-> solr-doc (.getChildDocuments) first (.hasChildDocuments)) => true))