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

Method tryToCreateIndex

search-meilisearch/index.go:28–53  ·  view source on GitHub ↗

try to create index if not exist

()

Source from the content-addressed store, hash-verified

26
27// try to create index if not exist
28func (s *Search) tryToCreateIndex() {
29 index, err := s.Client.GetIndex(s.Config.IndexName)
30 if index != nil {
31 log.Infof("index %s already exist, skip create", s.Config.IndexName)
32 return
33 }
34 if err != nil && index == nil {
35 log.Infof("get index failed %s, maybe not exist, try to create", err)
36 }
37
38 log.Infof("try to create index %s", s.Config.IndexName)
39 resp, err := s.Client.CreateIndex(&meilisearch.IndexConfig{
40 Uid: s.Config.IndexName,
41 PrimaryKey: primaryKey,
42 })
43 if err != nil {
44 log.Errorf("create index error: %s", err.Error())
45 return
46 }
47 if err = waitForTask(s.Client, resp); err != nil {
48 log.Errorf("create index error: %s", err.Error())
49 } else {
50 log.Infof("create index %s success", s.Config.IndexName)
51 }
52 return
53}

Callers 1

ConfigReceiverMethod · 0.95

Calls 2

waitForTaskFunction · 0.85
CreateIndexMethod · 0.80

Tested by

no test coverage detected