diff --git a/README.md b/README.md index b97f25b8..eb2d09d0 100644 --- a/README.md +++ b/README.md @@ -433,19 +433,10 @@ docker run -d --name meili -v ${PWD}/data/meili/data:/meili_data -p 7700:7700 -e # 使用docker compose运行,需要删除docker-compose.yaml中关于meili的注释 docker compose up -d meili -# 使用docker运行meilisearch的ui管理前端 -docker run -d --name uirecord -p 7701:3000 bitriory/uirecord -# visit http://localhost:7701 - -# 使用docker compose运行meilisearch的ui管理前端,需要删除docker-compose.yaml中关于uirecord的注释 -docker compose up -d uirecord -# visit http://loclahost:7701 - # 查看meili运行状态 docker compose ps NAME COMMAND SERVICE STATUS PORTS paopao-ce-meili-1 "tini -- /bin/sh -c …" meili running 0.0.0.0:7700->7700/tcp -paopao-ce-uirecord-1 "docker-entrypoint.s…" uirecord running 0.0.0.0:7701->3000/tcp ``` * 修改Meili配置 diff --git a/internal/dao/search/meili.go b/internal/dao/search/meili.go index e3160280..fc19e358 100644 --- a/internal/dao/search/meili.go +++ b/internal/dao/search/meili.go @@ -59,12 +59,12 @@ func (s *meiliTweetSearchServant) IndexName() string { return s.index.UID } -func (s *meiliTweetSearchServant) AddDocuments(data []core.TsDocItem, primaryKey ...string) (bool, error) { +func (s *meiliTweetSearchServant) AddDocuments(data []core.TsDocItem, _primaryKey ...string) (bool, error) { docs := s.toDocs(data) if len(docs) == 0 { return true, nil } - if _, err := s.index.AddDocuments(docs, primaryKey...); err != nil { + if _, err := s.index.AddDocuments(docs); err != nil { logrus.Errorf("meiliTweetSearchServant.AddDocuments error: %s", err) return false, err } diff --git a/internal/dao/search/search.go b/internal/dao/search/search.go index 3a7e4f72..d8a058f8 100644 --- a/internal/dao/search/search.go +++ b/internal/dao/search/search.go @@ -22,19 +22,22 @@ func NewMeiliTweetSearchService(ams core.AuthorizationManageService) (core.Tweet }) if _, err := client.Index(s.Index).FetchInfo(); err != nil { - logrus.Debugf("create index because fetch index info error: %v", err) - client.CreateIndex(&meilisearch.IndexConfig{ + logrus.Debugf("create meili index because fetch index info error: %v", err) + if _, err := client.CreateIndex(&meilisearch.IndexConfig{ Uid: s.Index, PrimaryKey: "id", - }) - searchableAttributes := []string{"content", "tags"} - sortableAttributes := []string{"is_top", "latest_replied_on"} - filterableAttributes := []string{"tags", "visibility", "user_id"} - - index := client.Index(s.Index) - index.UpdateSearchableAttributes(&searchableAttributes) - index.UpdateSortableAttributes(&sortableAttributes) - index.UpdateFilterableAttributes(&filterableAttributes) + }); err == nil { + settings := meilisearch.Settings{ + SearchableAttributes: []string{"content", "tags"}, + SortableAttributes: []string{"is_top", "latest_replied_on"}, + FilterableAttributes: []string{"tags", "visibility", "user_id"}, + } + if _, err = client.Index(s.Index).UpdateSettings(&settings); err != nil { + logrus.Errorf("update meili settings error: %s", err) + } + } else { + logrus.Errorf("create meili index error: %s", err) + } } mts := &meiliTweetSearchServant{