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

Method ConfigReceiver

search-meilisearch/meilisearch.go:226–267  ·  view source on GitHub ↗
(config []byte)

Source from the content-addressed store, hash-verified

224}
225
226func (s *Search) ConfigReceiver(config []byte) error {
227 conf := &SearchConfig{}
228 _ = json.Unmarshal(config, conf)
229
230 // if index name is empty, use default index name
231 if conf.IndexName == "" {
232 conf.IndexName = defaultIndexName
233 }
234 s.Config = conf
235
236 log.Debugf("try to init meilisearch client: %s", conf.Host)
237
238 s.Client = meilisearch.NewClient(meilisearch.ClientConfig{
239 Host: conf.Host,
240 APIKey: conf.ApiKey,
241 })
242
243 s.tryToCreateIndex()
244
245 index := s.Client.Index(conf.IndexName)
246 _, err := index.UpdateSearchableAttributes(&[]string{"title", "content"})
247 if err != nil {
248 log.Errorf("update searchable attributes error: %s", err.Error())
249 return err
250 }
251 _, err = index.UpdateFilterableAttributes(&[]string{"title", "content", "tags", "status", "answers", "type", "questionID", "userID", "views", "created", "active", "score", "hasAccepted"})
252 if err != nil {
253 log.Errorf("update filterable attributes error: %s", err.Error())
254 return err
255 }
256 _, err = index.UpdateSortableAttributes(&[]string{"active", "created", "active", "score"})
257 if err != nil {
258 log.Errorf("update sortable attributes error: %s", err.Error())
259 return err
260 }
261 _, err = index.UpdateDisplayedAttributes(&[]string{"title", "content", "objectID", "type"})
262 if err != nil {
263 log.Errorf("update displayed attributes error: %s", err.Error())
264 return err
265 }
266 return nil
267}
268
269func (s *Search) warpResult(resp *meilisearch.SearchResponse) ([]plugin.SearchResult, int64, error) {
270 res := make([]plugin.SearchResult, 0)

Callers

nothing calls this directly

Calls 1

tryToCreateIndexMethod · 0.95

Tested by

no test coverage detected