| 135 | } |
| 136 | |
| 137 | func (r *IndexClient) DocCount() (uint64, error) { |
| 138 | if r.CountURL == "" { |
| 139 | return 0, fmt.Errorf("remote: no CountURL provided") |
| 140 | } |
| 141 | u, err := UrlWithAuth(r.AuthType(), r.CountURL) |
| 142 | if err != nil { |
| 143 | return 0, fmt.Errorf("remote: auth for count,"+ |
| 144 | " countURL: %s, authType: %s, err: %v", |
| 145 | r.CountURL, r.AuthType(), err) |
| 146 | } |
| 147 | |
| 148 | resp, err := HttpGet(r.httpClient, u) |
| 149 | if err != nil { |
| 150 | return 0, err |
| 151 | } |
| 152 | defer resp.Body.Close() |
| 153 | |
| 154 | respBuf, err := ioutil.ReadAll(resp.Body) |
| 155 | if err != nil { |
| 156 | return 0, fmt.Errorf("remote: count error reading resp.Body,"+ |
| 157 | " countURL: %s, resp: %#v, err: %v", r.CountURL, resp, err) |
| 158 | } |
| 159 | |
| 160 | if resp.StatusCode != 200 { |
| 161 | return 0, fmt.Errorf("remote: count got status code: %d,"+ |
| 162 | " countURL: %s, resp: %#v", resp.StatusCode, r.CountURL, resp) |
| 163 | } |
| 164 | |
| 165 | rv := struct { |
| 166 | Status string `json:"status"` |
| 167 | Count uint64 `json:"count"` |
| 168 | }{} |
| 169 | err = UnmarshalJSON(respBuf, &rv) |
| 170 | if err != nil { |
| 171 | return 0, fmt.Errorf("remote: count error parsing respBuf: %s,"+ |
| 172 | " countURL: %s, resp: %#v, err: %v", |
| 173 | respBuf, r.CountURL, resp, err) |
| 174 | } |
| 175 | |
| 176 | return rv.Count, nil |
| 177 | } |
| 178 | |
| 179 | func (r *IndexClient) Search(req *bleve.SearchRequest) ( |
| 180 | *bleve.SearchResult, error) { |