1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package logic
- import (
- cm "app.yhyue.com/moapp/jybase/common"
- elastic "app.yhyue.com/moapp/jybase/esv1"
- "context"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- . "knowledgeBase/rpc/knowledge/init"
- "knowledgeBase/rpc/knowledge/internal/svc"
- "knowledgeBase/rpc/knowledge/knowledgeclient"
- "knowledgeBase/rpc/knowledge/util"
- )
- type FindAnswerLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewFindAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindAnswerLogic {
- return &FindAnswerLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *FindAnswerLogic) FindAnswer(in *knowledgeclient.FindAnswerReq) (*knowledgeclient.FindAnswerResp, error) {
- var question *knowledgeclient.Question
- //组装es query
- query := util.DSL4SmartResponse(in.Question, in.TenantId, int(in.Type))
- fmt.Println("query:", query)
- res := elastic.Get(C.Es.Index, C.Es.Type, query)
- if res != nil && len(*res) > 0 {
- data := (*res)[0]
- question.XId = cm.ObjToString(data["_id"])
- question.Answer = cm.ObjToString(data["answer"])
- question.Question = cm.ObjToString(data["question"])
- }
- fmt.Println("根据问题匹配答案:", question)
- return &knowledgeclient.FindAnswerResp{
- ErrorCode: 0,
- ErrorMsg: "请求成功",
- Data: question,
- }, nil
- }
|