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+)"
|
||||
(: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.
|
||||
|
|
|
|||
|
|
@ -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))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue