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

Method documentMatchHandler

stream.go:139–213  ·  view source on GitHub ↗
(hit *search.DocumentMatch)

Source from the content-addressed store, hash-verified

137}
138
139func (dmh *docMatchHandler) documentMatchHandler(hit *search.DocumentMatch) error {
140 if hit != nil {
141 /***** remove unnecessary fields *****/
142 if dmh.s.req.Highlight == nil {
143 if !dmh.s.req.IncludeLocations {
144 hit.Locations = nil
145 }
146
147 hit.Fragments = nil
148 }
149
150 if len(dmh.s.req.Fields) == 0 {
151 hit.Fields = nil
152 }
153
154 if !dmh.s.req.Explain {
155 hit.Expl = nil
156 }
157 /***** removed unnecessary fields *****/
158
159 if dmh.s.req.IncludeLocations || dmh.s.req.Highlight != nil {
160 hit.Complete(nil)
161 }
162
163 if len(dmh.s.req.Fields) > 0 || dmh.highlighter != nil {
164 bleve.LoadAndHighlightFields(hit, dmh.s.req, "", dmh.ctx.IndexReader,
165 dmh.highlighter)
166 }
167
168 // If this is a multi collection index, then strip the colelction UID
169 // from the hit ID.
170 if dmh.collNameMap != nil {
171 idBytes := []byte(hit.ID)
172 cuid := binary.LittleEndian.Uint32(idBytes[:4])
173 if collName, ok := dmh.collNameMap[cuid]; ok {
174 hit.ID = string(idBytes[4:])
175 if hit.Fields == nil {
176 hit.Fields = make(map[string]interface{})
177 }
178 hit.Fields["_$c"] = collName
179 }
180 }
181
182 // TODO: perf, perhaps encode directly into output buffer
183 // (dmh.bits?) instead of alloc'ing memory and copying?
184 b, err := MarshalJSON(hit)
185 if err != nil {
186 log.Printf("streamHandler: json marshal err: %v", err)
187 return err
188 }
189
190 if dmh.n > 0 {
191 dmh.bhits = append(append(dmh.bhits, itemGlue...), b...)
192 } else {
193 dmh.bhits = append(dmh.bhits, b...)
194 }
195 // remember the ending offset position
196 dmh.offsets = append(dmh.offsets, uint64(len(dmh.bhits)))

Callers

nothing calls this directly

Calls 2

MarshalJSONFunction · 0.85
writeMethod · 0.65

Tested by

no test coverage detected