From f7f6ff743ad8d297fa3b207e72e153b0833a6a82 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 1 Oct 2018 17:45:21 +0300 Subject: [PATCH 1/2] index trackExistence is true by default --- http/handler.go | 14 ++++++++++++-- http/handler_internal_test.go | 7 ++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/http/handler.go b/http/handler.go index 820bc6521..c5e8d5b18 100644 --- a/http/handler.go +++ b/http/handler.go @@ -521,7 +521,12 @@ func (p *postIndexRequest) UnmarshalJSON(b []byte) error { return err } // Unmarshal expected values. - var _p _postIndexRequest + _p := _postIndexRequest{ + Options: pilosa.IndexOptions{ + Keys: false, + TrackExistence: true, + }, + } if err := json.Unmarshal(b, &_p); err != nil { return errors.Wrap(err, "unmarshalling expected values") } @@ -597,7 +602,12 @@ func (h *Handler) handlePostIndex(w http.ResponseWriter, r *http.Request) { resp := successResponse{} // Decode request. - var req postIndexRequest + req := postIndexRequest{ + Options: pilosa.IndexOptions{ + Keys: false, + TrackExistence: true, + }, + } err := json.NewDecoder(r.Body).Decode(&req) if err != nil && err != io.EOF { resp.write(w, err) diff --git a/http/handler_internal_test.go b/http/handler_internal_test.go index b0852a79d..7ca9c0401 100644 --- a/http/handler_internal_test.go +++ b/http/handler_internal_test.go @@ -31,8 +31,9 @@ func TestPostIndexRequestUnmarshalJSON(t *testing.T) { expected postIndexRequest err string }{ - {json: `{"options": {}}`, expected: postIndexRequest{Options: pilosa.IndexOptions{}}}, - {json: `{"options": {"keys": true}}`, expected: postIndexRequest{Options: pilosa.IndexOptions{Keys: true}}}, + {json: `{"options": {}}`, expected: postIndexRequest{Options: pilosa.IndexOptions{TrackExistence: true}}}, + {json: `{"options": {"trackExistence": false}}`, expected: postIndexRequest{Options: pilosa.IndexOptions{TrackExistence: false}}}, + {json: `{"options": {"keys": true}}`, expected: postIndexRequest{Options: pilosa.IndexOptions{Keys: true, TrackExistence: true}}}, {json: `{"options": 4}`, err: "options is not map[string]interface{}"}, {json: `{"option": {}}`, err: "Unknown key: option:map[]"}, {json: `{"options": {"badKey": "test"}}`, err: "Unknown key: badKey:test"}, @@ -53,7 +54,7 @@ func TestPostIndexRequestUnmarshalJSON(t *testing.T) { if test.err == "" { if !reflect.DeepEqual(*actual, test.expected) { - t.Errorf("expected: %v, but got: %v", test.expected, *actual) + t.Errorf("expected: %v, but got: %v for JSON: %s", test.expected, *actual, test.json) } } From 432c2b5506d572ea2aedd7ca2a6c20ecbabc9bd0 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Wed, 3 Oct 2018 17:32:22 +0300 Subject: [PATCH 2/2] set trackExistence to true in NewIndex --- index.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.go b/index.go index 0992ab213..297c02f20 100644 --- a/index.go +++ b/index.go @@ -69,9 +69,10 @@ func NewIndex(path, name string) (*Index, error) { newAttrStore: newNopAttrStore, columnAttrs: nopStore, - broadcaster: NopBroadcaster, - Stats: NopStatsClient, - logger: NopLogger, + broadcaster: NopBroadcaster, + Stats: NopStatsClient, + logger: NopLogger, + trackExistence: true, }, nil }