fetcher/i2es/topics.go
2018-01-08 08:54:18 +03:00

50 lines
976 B
Go

package i2es
import (
log "github.com/Sirupsen/logrus"
"github.com/google/uuid"
)
// AssignTopics ...
func (es ESConf) AssignTopics(messages []ESDoc) error {
for _, message := range messages {
// generate new topicid
if message.Repto == "" && message.TopicID == "" {
message.TopicID = uuid.New().String()
err := es.PutToIndex(message)
if err != nil {
log.Error(err.Error())
continue
}
}
// skip message with assigned topicid
if message.TopicID != "" {
continue
}
// find top message of the thread and get they topicid
if message.Repto != "" {
t := topicid{es}
topicid, err := t.findTopicID(message.MsgID, 0)
if err != nil {
message.Misplaced = "yes"
err := es.PutToIndex(message)
if err != nil {
log.Error(err.Error())
continue
}
continue
}
message.TopicID = topicid
err = es.PutToIndex(message)
if err != nil {
log.Error(err.Error())
continue
}
}
}
return nil
}