try to create index if not exist
()
| 26 | |
| 27 | // try to create index if not exist |
| 28 | func (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 | } |
no test coverage detected