Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement percolation

  • Loading branch information...
commit 06dab41e61e11147dacf258ee2ff7eba799e2ad8 1 parent 452c94b
@michaelklishin michaelklishin authored
View
15 project.clj
@@ -1,6 +1,6 @@
(defproject clojurewerkz/elastisch "1.0.0-SNAPSHOT"
:url "http://clojureelasticsearch.info"
- :description "Clojure ElasticSearch client"
+ :description "Minimalistic fully featured well documented Clojure ElasticSearch client"
:license {:name "Eclipse Public License"}
:dependencies [[org.clojure/clojure "1.4.0"]
[cheshire "4.0.2"]
@@ -12,15 +12,16 @@
:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
:1.5 {:dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]}}
:aliases {"all" ["with-profile" "dev:dev,1.3:dev,1.5"]}
- :repositories {"sonatype" { :url "http://oss.sonatype.org/content/repositories/releases"
+ :repositories {"sonatype" {:url "http://oss.sonatype.org/content/repositories/releases"
:snapshots false
:releases {:checksum :fail :update :always}}
"sonatype-snapshots" {:url "http://oss.sonatype.org/content/repositories/snapshots"
:snapshots true
:releases {:checksum :fail :update :always}}}
:warn-on-reflection true
- :test-selectors {:focus :focus
- :indexing :indexing
- :query :query
- :facets :facets
- :all (constantly true)})
+ :test-selectors {:focus :focus
+ :indexing :indexing
+ :query :query
+ :facets :facets
+ :percolation :percolation
+ :all (constantly true)})
View
7 src/clojurewerkz/elastisch/rest.clj
@@ -179,6 +179,13 @@
[^String index-name ^String mapping-type id]
(join slash [(:uri *endpoint*) index-name mapping-type id "_mlt"]))
+(defn percolator-url
+ [^String index-name ^String percolator]
+ (join slash [(:uri *endpoint*) "_percolator" index-name percolator]))
+
+(defn index-percolation-url
+ [^String index-name ^String percolator]
+ (join slash [(:uri *endpoint*) index-name percolator "_percolate" ]))
;;
;; API
View
24 src/clojurewerkz/elastisch/rest/percolation.clj
@@ -0,0 +1,24 @@
+(ns clojurewerkz.elastisch.rest.percolation
+ (:require [clojurewerkz.elastisch.rest :as rest]
+ [cheshire.core :as json]))
+
+;;
+;; API
+;;
+
+(defn register
+ "Registers a percolator for the given index"
+ [index percolator & {:as options}]
+ (rest/put (rest/percolator-url index percolator) :body options))
+
+(defn unregister
+ "Unregisters a percolator for the given index"
+ [index percolator]
+ (rest/delete (rest/percolator-url index percolator)))
+
+(defn percolate
+ ""
+ [index percolator & {:as options}]
+ ;; rest/get won't serialize the body for us because we don't use GET requests
+ ;; w/ body for other features. MK.
+ (rest/get (rest/index-percolation-url index percolator) :body (json/encode options)))
View
5 src/clojurewerkz/elastisch/rest/response.clj
@@ -64,3 +64,8 @@
(if (any-hits? response)
(set (map :_id (hits-from response)))
#{}))
+
+(defn matches-from
+ "Returns matches from a percolation response as a collection."
+ [response]
+ (get response :matches []))
View
21 test/clojurewerkz/elastisch/rest_api/percolation_test.clj
@@ -0,0 +1,21 @@
+(ns clojurewerkz.elastisch.rest-api.percolation-test
+ (:require [clojurewerkz.elastisch.rest.document :as doc]
+ [clojurewerkz.elastisch.rest :as rest]
+ [clojurewerkz.elastisch.rest.index :as idx]
+ [clojurewerkz.elastisch.query :as q]
+ [clojurewerkz.elastisch.fixtures :as fx]
+ [clojurewerkz.elastisch.rest.percolation :as pcl])
+ (:use clojure.test clojurewerkz.elastisch.rest.response))
+
+
+(use-fixtures :each fx/reset-indexes fx/prepopulate-articles-index)
+
+(deftest ^{:percolation true} test-percolation-case-1
+ (let [index-name "articles"
+ percolator "article"
+ result1 (pcl/register index-name percolator :query {:term {:title "search"}})
+ result2 (pcl/percolate index-name percolator :doc {:title "You know, for search"})]
+ (is (ok? result1))
+ (is (ok? result2))
+ (is (= ["article"] (matches-from result2)))
+ (is (ok? (pcl/unregister index-name percolator)))))
Please sign in to comment.
Something went wrong with that request. Please try again.