From 767062ab7cdaa3812d9197d816f9f4c638a046a3 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Fri, 1 Mar 2019 14:57:46 +0300 Subject: [PATCH 1/2] Adds shardWidth to index info in schema --- holder.go | 6 +++++- server/handler_test.go | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/holder.go b/holder.go index 471d4bd3e..967664168 100644 --- a/holder.go +++ b/holder.go @@ -287,7 +287,11 @@ func (h *Holder) Schema() []*IndexInfo { func (h *Holder) limitedSchema() []*IndexInfo { var a []*IndexInfo for _, index := range h.Indexes() { - di := &IndexInfo{Name: index.Name(), Options: index.Options()} + di := &IndexInfo{ + Name: index.Name(), + Options: index.Options(), + ShardWidth: ShardWidth, + } for _, field := range index.Fields() { if strings.HasPrefix(field.name, "_") { continue diff --git a/server/handler_test.go b/server/handler_test.go index f6652632d..b8e4e6c4f 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -82,9 +82,12 @@ func TestHandler_Endpoints(t *testing.T) { h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", nil)) if w.Code != gohttp.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) - } else if body := w.Body.String(); body != `{"indexes":[{"name":"i0","fields":[{"name":"f0"},{"name":"f1","views":[{"name":"standard"}]}]},{"name":"i1","fields":[{"name":"f0","views":[{"name":"standard"}]}]}]}`+"\n" { - } else if body := w.Body.String(); body != `{"indexes":[{"name":"i0","fields":[{"name":"f0","options":{"cacheType":"ranked","cacheSize":50000}},{"name":"f1","options":{"cacheType":"ranked","cacheSize":50000},"views":[{"name":"standard"}]}]},{"name":"i1","fields":[{"name":"f0","options":{"cacheType":"ranked","cacheSize":50000},"views":[{"name":"standard"}]}]}]}`+"\n" { - t.Fatalf("unexpected body: %s", body) + } + body := w.Body.String() + target := `{"indexes":[{"name":"i0","options":{"keys":false,"trackExistence":false},"fields":[{"name":"f0","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}},{"name":"f1","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":1048576},{"name":"i1","options":{"keys":false,"trackExistence":false},"fields":[{"name":"f0","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":1048576}]} +` + if body != target { + t.Fatalf("%s != %s", target, body) } }) From d8ba398dd8aa192126b820c7d62eeaf73c7a8759 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Fri, 1 Mar 2019 15:02:49 +0300 Subject: [PATCH 2/2] added missing index.go changes --- index.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.go b/index.go index e06ce1732..696e81769 100644 --- a/index.go +++ b/index.go @@ -453,9 +453,10 @@ func (p indexSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() } // IndexInfo represents schema information for an index. type IndexInfo struct { - Name string `json:"name"` - Options IndexOptions `json:"options"` - Fields []*FieldInfo `json:"fields"` + Name string `json:"name"` + Options IndexOptions `json:"options"` + Fields []*FieldInfo `json:"fields"` + ShardWidth uint64 `json:"shardWidth"` } type indexInfoSlice []*IndexInfo