MCPcopy Create free account
hub / github.com/apache/answer-plugins / SearchAnswers

Method SearchAnswers

search-algolia/algolia.go:173–218  ·  view source on GitHub ↗
(ctx context.Context, cond *plugin.SearchBasicCond)

Source from the content-addressed store, hash-verified

171}
172
173func (s *SearchAlgolia) SearchAnswers(ctx context.Context, cond *plugin.SearchBasicCond) (res []plugin.SearchResult, total int64, err error) {
174 var (
175 filters = "status<10 AND type:answer"
176 tagFilters []string
177 userIDFilter string
178 questionIDFilter string
179 )
180 if len(cond.TagIDs) > 0 {
181 for _, tagID := range cond.TagIDs {
182 tagFilters = append(tagFilters, "tags:"+tagID)
183 }
184 if len(tagFilters) > 0 {
185 filters += " AND " + strings.Join(tagFilters, " AND ")
186 }
187 }
188 if cond.AnswerAccepted == plugin.AcceptedCondTrue {
189 userIDFilter = "hasAccepted=true"
190 filters += " AND " + userIDFilter
191 }
192
193 if len(cond.QuestionID) > 0 {
194 questionIDFilter = "questionID=" + cond.QuestionID
195 filters += questionIDFilter
196 }
197
198 var (
199 query = strings.TrimSpace(strings.Join(cond.Words, " "))
200 opts = []interface{}{
201 opt.AttributesToRetrieve("objectID", "type"),
202 opt.Filters(filters),
203 opt.Page(cond.Page - 1),
204 opt.HitsPerPage(cond.PageSize),
205 }
206 qres search.QueryRes
207 )
208
209 qres, err = s.getIndex(string(cond.Order)).Search(query, opts...)
210 for _, hit := range qres.Hits {
211 res = append(res, plugin.SearchResult{
212 ID: hit["objectID"].(string),
213 Type: hit["type"].(string),
214 })
215 }
216 total = int64(qres.NbHits)
217 return res, total, err
218}
219
220// UpdateContent updates the content to algolia server
221func (s *SearchAlgolia) UpdateContent(ctx context.Context, content *plugin.SearchContent) (err error) {

Callers

nothing calls this directly

Calls 1

getIndexMethod · 0.95

Tested by

no test coverage detected