MCPcopy Create free account
hub / github.com/couchbase/cbft / SearchInContext

Method SearchInContext

remote.go:184–266  ·  view source on GitHub ↗
(ctx context.Context,
	req *bleve.SearchRequest)

Source from the content-addressed store, hash-verified

182}
183
184func (r *IndexClient) SearchInContext(ctx context.Context,
185 req *bleve.SearchRequest) (*bleve.SearchResult, error) {
186 if req == nil {
187 return nil, fmt.Errorf("remote: no req provided")
188 }
189
190 if r.QueryURL == "" {
191 return nil, fmt.Errorf("remote: no QueryURL provided")
192 }
193
194 queryCtlParams := &cbgt.QueryCtlParams{
195 Ctl: cbgt.QueryCtl{
196 Consistency: r.Consistency,
197 },
198 }
199
200 queryPIndexes := &QueryPIndexes{
201 PIndexNames: r.PIndexNames,
202 }
203
204 // if timeout was set, compute time remaining
205 if deadline, ok := ctx.Deadline(); ok {
206 remaining := deadline.Sub(time.Now())
207 // FIXME arbitrarily reducing the timeout, to increase the liklihood
208 // that a live system replies via HTTP round-trip before we give up
209 // on the request externally
210 remaining -= RemoteRequestOverhead
211 if remaining <= 0 {
212 // not enough time left
213 return nil, context.DeadlineExceeded
214 }
215 queryCtlParams.Ctl.Timeout = int64(remaining / time.Millisecond)
216 }
217
218 buf, err := MarshalJSON(struct {
219 *cbgt.QueryCtlParams
220 *QueryPIndexes
221 *bleve.SearchRequest
222 }{
223 queryCtlParams,
224 queryPIndexes,
225 req,
226 })
227 if err != nil {
228 return nil, err
229 }
230
231 resultCh := make(chan *bleve.SearchResult, 1)
232
233 go func() {
234 respBuf, err := r.Query(buf)
235 if err != nil {
236 log.Warnf("remote: Query() returned error from host: %v,"+
237 " err: %v", r.HostPort, err)
238 resultCh <- makeSearchResultErr(req, r.PIndexNames, err)
239 return
240 }
241

Callers 6

SearchMethod · 0.95
deleteByQueryMethod · 0.45
QueryBleveFunction · 0.45
QueryMethod · 0.45
SearchMethod · 0.45
QueryAliasFunction · 0.45

Calls 4

QueryMethod · 0.95
MarshalJSONFunction · 0.85
makeSearchResultErrFunction · 0.85
UnmarshalJSONFunction · 0.85

Tested by

no test coverage detected