fixed zinc search engine add documents failure

pull/191/head
Michael Li 2 years ago
parent 4c0cfdd2b0
commit 87d9f61792

@ -256,13 +256,12 @@ func (s *zincTweetSearchServant) createIndex() {
}
func (s *zincTweetSearchServant) toDocs(data []core.TsDocItem) []map[string]any {
docs := make([]map[string]any, len(data))
docs := make([]map[string]any, 0, len(data))
for _, d := range data {
tagMaps := map[string]int8{}
for _, tag := range strings.Split(d.Post.Tags, ",") {
tagMaps[tag] = 1
}
docs = append(docs, map[string]any{
"id": d.Post.ID,
"user_id": d.Post.UserID,

@ -502,6 +502,8 @@ func DeleteSearchPost(post *model.Post) error {
func PushPostsToSearch(c *gin.Context) {
if ok, _ := conf.Redis.SetNX(c, "JOB_PUSH_TO_SEARCH", 1, time.Hour).Result(); ok {
defer conf.Redis.Del(c, "JOB_PUSH_TO_SEARCH")
splitNum := 1000
totalRows, _ := GetPostCount(&model.ConditionsT{
"visibility IN ?": []model.PostVisibleT{model.PostVisitPublic, model.PostVisitFriend},
@ -533,8 +535,6 @@ func PushPostsToSearch(c *gin.Context) {
ts.AddDocuments(docs, fmt.Sprintf("%d", posts[i].ID))
}
}
conf.Redis.Del(c, "JOB_PUSH_TO_SEARCH")
}
}

Loading…
Cancel
Save