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

Function QueryAlias

pindex_alias.go:92–143  ·  view source on GitHub ↗
(mgr *cbgt.Manager, indexName, indexUUID string,
	req []byte, res io.Writer)

Source from the content-addressed store, hash-verified

90}
91
92func QueryAlias(mgr *cbgt.Manager, indexName, indexUUID string,
93 req []byte, res io.Writer) error {
94 queryCtlParams := cbgt.QueryCtlParams{
95 Ctl: cbgt.QueryCtl{
96 Timeout: cbgt.QUERY_CTL_DEFAULT_TIMEOUT_MS,
97 },
98 }
99
100 err := UnmarshalJSON(req, &queryCtlParams)
101 if err != nil {
102 return fmt.Errorf("alias: QueryAlias"+
103 " parsing queryCtlParams, err: %v", err)
104 }
105
106 var sr *SearchRequest
107 err = UnmarshalJSON(req, &sr)
108 if err != nil {
109 return fmt.Errorf("alias: QueryAlias"+
110 " parsing searchRequest, err: %v", err)
111 }
112 searchRequest, err := sr.ConvertToBleveSearchRequest()
113 if err != nil {
114 return fmt.Errorf("alias: QueryAlias"+
115 " parsing searchRequest, err: %v", err)
116 }
117
118 ctx, cancel, cancelCh := setupContextAndCancelCh(queryCtlParams, nil)
119 // defer a call to cancel, this ensures that goroutine from
120 // setupContextAndCancelCh always exits
121 defer cancel()
122
123 alias, multiCollIndex, err := bleveIndexAliasForUserIndexAlias(mgr,
124 indexName, indexUUID, true,
125 queryCtlParams.Ctl.Consistency, cancelCh, true,
126 queryCtlParams.Ctl.PartitionSelection)
127 if err != nil {
128 return err
129 }
130
131 searchResponse, err := alias.SearchInContext(ctx, searchRequest)
132 if err != nil {
133 return err
134 }
135 // additional processing with multi-collection indexes.
136 if multiCollIndex {
137 processAliasResponse(searchResponse)
138 }
139
140 rest.MustEncode(res, searchResponse)
141
142 return nil
143}
144
145func processAliasResponse(searchResponse *bleve.SearchResult) {
146 if searchResponse != nil {

Callers

nothing calls this directly

Calls 6

UnmarshalJSONFunction · 0.85
setupContextAndCancelChFunction · 0.85
processAliasResponseFunction · 0.85
SearchInContextMethod · 0.45

Tested by

no test coverage detected