-
-
Save tomjack/addee4abcf949e445093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns parasol.solr-wrapper | |
(:import org.apache.solr.common.SolrInputDocument | |
org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) | |
(:use [parasol.json :only (json-request)])) | |
(defn- add-field [solr-doc [k v]] | |
(doto solr-doc | |
(.addField (if (keyword? k) | |
(name k) | |
k) | |
v))) | |
(defn solr-doc [m] | |
(reduce add-field (SolrInputDocument.) m)) | |
(def *default-solr-url* "http://localhost:8983/solr") | |
(defn solr-server | |
([] | |
(solr-server *default-solr-url*)) | |
([solr-url] | |
(CommonsHttpSolrServer. solr-url))) | |
(defn index-docs [server docs] | |
(if (seq docs) | |
(doto server | |
(.add (map solr-doc docs)) | |
(.commit)))) | |
(defn solr-search | |
([params] | |
(solr-search *default-solr-url* params)) | |
([solr-url params] | |
(let [search-path (str solr-url "/select/")] | |
(json-request search-path | |
(merge {:wt "json"} | |
params))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment