|
@@ -249,13 +249,14 @@ func (k *KnowledgeService) FindAnswer(param *knowledgeclient.FindAnswerReq, addr
|
|
|
robotEntId := SE.Decode4Hex(param.RobotEntId)
|
|
|
//组装es query
|
|
|
query := util.DSL4SmartResponse(param.Question, robotEntId, int(param.Type), addr, index, segment)
|
|
|
-
|
|
|
- res := elastic.Get(Index, Type, query)
|
|
|
- log.Println("es查询:", res)
|
|
|
- if res != nil && len(*res) > 0 {
|
|
|
- data := (*res)[0]
|
|
|
- question.Answer = cm.ObjToString(data["answer"])
|
|
|
- question.Question = cm.ObjToString(data["question"])
|
|
|
+ logx.Info("query:", query)
|
|
|
+ if query != "" {
|
|
|
+ res := elastic.Get(Index, Type, query)
|
|
|
+ if res != nil && len(*res) > 0 {
|
|
|
+ data := (*res)[0]
|
|
|
+ question.Answer = cm.ObjToString(data["answer"])
|
|
|
+ question.Question = cm.ObjToString(data["question"])
|
|
|
+ }
|
|
|
}
|
|
|
return &question
|
|
|
}
|
|
@@ -267,22 +268,20 @@ func (k *KnowledgeService) RecommendAnswer(param *knowledgeclient.FindAnswerReq,
|
|
|
answers []*knowledgeclient.Question
|
|
|
)
|
|
|
//根据问题进行分词
|
|
|
- keywords := ""
|
|
|
keywordsArr := util.HanlpGetNormalWords(param.Question, segment)
|
|
|
log.Println("keywordsArr", keywordsArr)
|
|
|
if len(keywordsArr) != 0 {
|
|
|
for _, val := range keywordsArr {
|
|
|
- keywords += val + " "
|
|
|
+ keyWords += val + " "
|
|
|
}
|
|
|
}
|
|
|
- log.Println("问题分词关键字1:", len(keyWords))
|
|
|
- if keywords == "" {
|
|
|
- keywords += param.Question
|
|
|
+ if keyWords == "" {
|
|
|
+ keyWords = param.Question
|
|
|
}
|
|
|
log.Println("问题分词关键字2:", keyWords)
|
|
|
var query = util.DSL4SearchByKwsOrid(keyWords, SE.Decode4Hex(param.RobotEntId))
|
|
|
res := elastic.GetAllByNgram(Index, Type, query, "", "", searchField, 0, 3, 0, false)
|
|
|
- //log.Println("推荐3个答案:", res)
|
|
|
+ log.Println("推荐3个答案:", res)
|
|
|
if res != nil && len(*res) > 0 {
|
|
|
for _, val := range *res {
|
|
|
answers = append(answers, &knowledgeclient.Question{
|