diff --git a/src/typesense/api.clj b/src/typesense/api.clj index ca25c98..8e9aa0d 100644 --- a/src/typesense/api.clj +++ b/src/typesense/api.clj @@ -48,8 +48,9 @@ (defn- multi-search-uri "Returns the full multi-search uri resource path." - [uri common-search-parameters] - (str uri "/multi_search" (util/build-query common-search-parameters))) + [uri common-search-params opt-query-params] + (let [query-parameter-map (merge common-search-params opt-query-params)] + (str uri "/multi_search" (util/build-query query-parameter-map)))) (defn create-collection-req [{:keys [uri key]} schema] @@ -136,8 +137,8 @@ :req {:headers {api-key-header-name key}}}) (defn multi-search-req - [{:keys [uri key]} search-reqs common-search-params] - {:uri (multi-search-uri uri common-search-params) + [{:keys [uri key]} search-reqs common-search-params opt-query-params] + {:uri (multi-search-uri uri common-search-params opt-query-params) :req {:headers {api-key-header-name key "Content-Type" "application/json"} :body (json/write-str search-reqs)}}) diff --git a/src/typesense/client.clj b/src/typesense/client.clj index 6427a8e..801be4e 100644 --- a/src/typesense/client.clj +++ b/src/typesense/client.clj @@ -161,9 +161,9 @@ (defn multi-search "Search for documents in multiple collections." - [settings search-reqs common-search-params] + [settings search-reqs common-search-params & opt-query-params] (try+ - (let [{:keys [uri req]} (api/multi-search-req settings search-reqs common-search-params)] + (let [{:keys [uri req]} (api/multi-search-req settings search-reqs common-search-params opt-query-params)] (util/http-response-json->map (http/post uri req))) (catch [:type :clj-http.client/unexceptional-status] e (throw (http-ex-data->typesense-ex-info e))))) diff --git a/test/typesense/api_test.clj b/test/typesense/api_test.clj index 29973ae..d48e172 100644 --- a/test/typesense/api_test.clj +++ b/test/typesense/api_test.clj @@ -165,13 +165,29 @@ :filter_by "price:=[50..120]"} {:collection "brands" :q "Nike"}]} - {:query_by "name"}) + {:query_by "name"} + nil) exp {:uri "http://localhost:8108/multi_search?query_by=name" :req {:headers {"X-TYPESENSE-API-KEY" "key" "Content-Type" "application/json"} :body "{\"searches\":[{\"collection\":\"products\",\"q\":\"shoe\",\"filter_by\":\"price:=[50..120]\"},{\"collection\":\"brands\",\"q\":\"Nike\"}]}"}}] (is (= exp req)))) +(deftest multi-search-req-test-optional-parameter + (let [req (sut/multi-search-req settings + {:searches [{:collection "products" + :q "shoe" + :filter_by "price:=[50..120]"} + {:collection "brands" + :q "Nike"}]} + {:query_by "name"} + {:limit_multi_searches 100}) + exp {:uri "http://localhost:8108/multi_search?query_by=name&limit_multi_searches=100" + :req {:headers {"X-TYPESENSE-API-KEY" "key" + "Content-Type" "application/json"} + :body "{\"searches\":[{\"collection\":\"products\",\"q\":\"shoe\",\"filter_by\":\"price:=[50..120]\"},{\"collection\":\"brands\",\"q\":\"Nike\"}]}"}}] + (is (= exp req)))) + (deftest create-api-key-req-test (let [req (sut/create-api-key-req settings {:description "Search only companies key."