From d372602f3c09b36920a06342a924b4dc8a4e9a03 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Tue, 15 Nov 2016 10:29:11 -0500 Subject: [PATCH] add support for parsing BoolFieldQuery from JSON presence of the "bool" key triggers parsing as a BoolFieldQuery fixes #498 --- search/query/query.go | 9 +++++++++ search/query/query_test.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/search/query/query.go b/search/query/query.go index 7a4b0751..9e7a2e97 100644 --- a/search/query/query.go +++ b/search/query/query.go @@ -226,6 +226,15 @@ func ParseQuery(input []byte) (Query, error) { } return &rv, nil } + _, hasBool := tmp["bool"] + if hasBool { + var rv BoolFieldQuery + err := json.Unmarshal(input, &rv) + if err != nil { + return nil, err + } + return &rv, nil + } return nil, fmt.Errorf("unknown query type") } diff --git a/search/query/query_test.go b/search/query/query_test.go index 59e5ce60..09d25f14 100644 --- a/search/query/query_test.go +++ b/search/query/query_test.go @@ -170,6 +170,10 @@ func TestParseQuery(t *testing.T) { input: []byte(`{"ids":["a","b","c"]}`), output: NewDocIDQuery([]string{"a", "b", "c"}), }, + { + input: []byte(`{"bool": true}`), + output: NewBoolFieldQuery(true), + }, { input: []byte(`{"madeitup":"queryhere"}`), output: nil,