diff --git a/src/clojure/monger/search.clj b/src/clojure/monger/search.clj index c88e643..6682887 100644 --- a/src/clojure/monger/search.clj +++ b/src/clojure/monger/search.clj @@ -11,7 +11,7 @@ "Full text search queries support (MongoDB 2.4+)" (:require [monger.command :as cmd] [monger.conversion :as cnv]) - (:import [com.mongodb CommandResult BasicDBList DBObject])) + (:import [com.mongodb DB CommandResult BasicDBList DBObject])) ;; ;; Implementation @@ -28,8 +28,8 @@ (defn search "Performs a full text search query" - [^String collection query] - (cmd/search collection query)) + [^DB db ^String collection query] + (cmd/search db collection query)) (defn results-from "Returns a lazy sequence of results from a search query response, sorted by score. diff --git a/test/monger/test/full_text_search_test.clj b/test/monger/test/full_text_search_test.clj index d40cd87..321a5e1 100644 --- a/test/monger/test/full_text_search_test.clj +++ b/test/monger/test/full_text_search_test.clj @@ -3,33 +3,38 @@ [monger.collection :as mc] [monger.search :as ms] [monger.command :as cmd] - [monger.test.helper :as helper] [clojure.test :refer [deftest is use-fixtures]] - [monger.test.fixtures :refer :all] - [monger.result :refer [ok?]]) + [monger.result :refer [ok?]]) (:import com.mongodb.BasicDBObjectBuilder)) -(helper/connect!) +(let [conn (mg/connect) + db (mg/get-db conn "monger-test") + coll "search-docs"] -(defn enable-search - [f] - ;; {:textSearchEnabled true :setParameter 1} - (let [bldr (doto (BasicDBObjectBuilder.) - (.append "setParameter" 1) - (.append "textSearchEnabled" true)) - cmd (.get bldr)] - (is (ok? (cmd/raw-admin-command cmd)))) - (f)) + (defn enable-search + [f] + ;; {:textSearchEnabled true :setParameter 1} + (let [bldr (doto (BasicDBObjectBuilder.) + (.append "setParameter" 1) + (.append "textSearchEnabled" true)) + cmd (.get bldr)] + (is (ok? (cmd/raw-admin-command conn cmd)))) + (f)) -(use-fixtures :each purge-docs) -(use-fixtures :once enable-search) + (defn purge-collections + [f] + (mc/purge-many db [coll]) + (f) + (mc/purge-many db [coll])) -(deftest ^{:search true} test-basic-full-text-search-query - (let [coll "docs"] - (mc/ensure-index coll (array-map :subject "text" :content "text")) - (mc/insert coll {:subject "hello there" :content "this should be searchable"}) - (mc/insert coll {:subject "untitled" :content "this is just noize"}) - (let [res (ms/search coll "hello") + (use-fixtures :each purge-collections) + (use-fixtures :once enable-search) + + (deftest ^{:search true} test-basic-full-text-search-query + (mc/ensure-index db coll (array-map :subject "text" :content "text")) + (mc/insert db coll {:subject "hello there" :content "this should be searchable"}) + (mc/insert db coll {:subject "untitled" :content "this is just noize"}) + (let [res (ms/search db coll "hello") xs (ms/results-from res)] (is (= "hello there" (-> xs first :obj :subject))) (is (= 1.0 (-> xs first :score))))))