Search tests now pass
This commit is contained in:
parent
8b237db382
commit
a7cceebe9c
2 changed files with 29 additions and 24 deletions
|
|
@ -11,7 +11,7 @@
|
||||||
"Full text search queries support (MongoDB 2.4+)"
|
"Full text search queries support (MongoDB 2.4+)"
|
||||||
(:require [monger.command :as cmd]
|
(:require [monger.command :as cmd]
|
||||||
[monger.conversion :as cnv])
|
[monger.conversion :as cnv])
|
||||||
(:import [com.mongodb CommandResult BasicDBList DBObject]))
|
(:import [com.mongodb DB CommandResult BasicDBList DBObject]))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Implementation
|
;; Implementation
|
||||||
|
|
@ -28,8 +28,8 @@
|
||||||
|
|
||||||
(defn search
|
(defn search
|
||||||
"Performs a full text search query"
|
"Performs a full text search query"
|
||||||
[^String collection query]
|
[^DB db ^String collection query]
|
||||||
(cmd/search collection query))
|
(cmd/search db collection query))
|
||||||
|
|
||||||
(defn results-from
|
(defn results-from
|
||||||
"Returns a lazy sequence of results from a search query response, sorted by score.
|
"Returns a lazy sequence of results from a search query response, sorted by score.
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@
|
||||||
[monger.collection :as mc]
|
[monger.collection :as mc]
|
||||||
[monger.search :as ms]
|
[monger.search :as ms]
|
||||||
[monger.command :as cmd]
|
[monger.command :as cmd]
|
||||||
[monger.test.helper :as helper]
|
|
||||||
[clojure.test :refer [deftest is use-fixtures]]
|
[clojure.test :refer [deftest is use-fixtures]]
|
||||||
[monger.test.fixtures :refer :all]
|
|
||||||
[monger.result :refer [ok?]])
|
[monger.result :refer [ok?]])
|
||||||
(:import com.mongodb.BasicDBObjectBuilder))
|
(:import com.mongodb.BasicDBObjectBuilder))
|
||||||
|
|
||||||
(helper/connect!)
|
(let [conn (mg/connect)
|
||||||
|
db (mg/get-db conn "monger-test")
|
||||||
|
coll "search-docs"]
|
||||||
|
|
||||||
(defn enable-search
|
(defn enable-search
|
||||||
[f]
|
[f]
|
||||||
|
|
@ -18,18 +18,23 @@
|
||||||
(.append "setParameter" 1)
|
(.append "setParameter" 1)
|
||||||
(.append "textSearchEnabled" true))
|
(.append "textSearchEnabled" true))
|
||||||
cmd (.get bldr)]
|
cmd (.get bldr)]
|
||||||
(is (ok? (cmd/raw-admin-command cmd))))
|
(is (ok? (cmd/raw-admin-command conn cmd))))
|
||||||
(f))
|
(f))
|
||||||
|
|
||||||
(use-fixtures :each purge-docs)
|
(defn purge-collections
|
||||||
|
[f]
|
||||||
|
(mc/purge-many db [coll])
|
||||||
|
(f)
|
||||||
|
(mc/purge-many db [coll]))
|
||||||
|
|
||||||
|
(use-fixtures :each purge-collections)
|
||||||
(use-fixtures :once enable-search)
|
(use-fixtures :once enable-search)
|
||||||
|
|
||||||
(deftest ^{:search true} test-basic-full-text-search-query
|
(deftest ^{:search true} test-basic-full-text-search-query
|
||||||
(let [coll "docs"]
|
(mc/ensure-index db coll (array-map :subject "text" :content "text"))
|
||||||
(mc/ensure-index coll (array-map :subject "text" :content "text"))
|
(mc/insert db coll {:subject "hello there" :content "this should be searchable"})
|
||||||
(mc/insert coll {:subject "hello there" :content "this should be searchable"})
|
(mc/insert db coll {:subject "untitled" :content "this is just noize"})
|
||||||
(mc/insert coll {:subject "untitled" :content "this is just noize"})
|
(let [res (ms/search db coll "hello")
|
||||||
(let [res (ms/search coll "hello")
|
|
||||||
xs (ms/results-from res)]
|
xs (ms/results-from res)]
|
||||||
(is (= "hello there" (-> xs first :obj :subject)))
|
(is (= "hello there" (-> xs first :obj :subject)))
|
||||||
(is (= 1.0 (-> xs first :score))))))
|
(is (= 1.0 (-> xs first :score))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue