12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package logic
- import (
- "context"
- "github.com/zeromicro/go-zero/core/logx"
- "knowledgeBase/rpc/knowledge/internal/svc"
- "knowledgeBase/rpc/knowledge/knowledgeclient"
- )
- type RecommendAnswerLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewRecommendAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecommendAnswerLogic {
- return &RecommendAnswerLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *RecommendAnswerLogic) RecommendAnswer(in *knowledgeclient.FindAnswerReq) (*knowledgeclient.RecommendAnswerResp, error) {
- // todo: add your logic here and delete this line
- /*question := in.Question
- result := utils.HttpDo(in.Question)
- var resmap []map[string]interface{}
- json.Unmarshal([]byte(result), &resmap)
- pid := utils.BsonIdToSId(res["pid"])
- //log.Println(pid)
- rquery := map[string]interface{}{
- "platFormUserId": pid,
- }
- repository := repositoryService.FindByField(rquery)
- repositoryId := utils.BsonIdToSId(repository.Id)
- repositoryIdArr := getCiteRepository(pid)
- var strr string
- if len(repositoryIdArr) > 0 {
- strr = "," + "\"" + repositoryId + "\""
- } else {
- strr = "\"" + repositoryId + "\""
- }
- repositoryIdArr = append(repositoryIdArr, strr)
- var kws = ""
- var link_obj = &[]map[string]interface{}{}
- if len(resmap) > 0 {
- for k, v := range resmap {
- if strings.Contains(v["nature"].(string), "n") && len(v["word"].(string)) > 3 {
- if k > 0 && len(kws) > 1 {
- kws += " "
- }
- kws += v["word"].(string)
- }
- }
- }
- //fmt.Println("关键字:", kws)
- var search_field = `"_id","knowledgeKeyWords","answer","relativeKnowledgeId","createUser","tags","questions","repositoryId","createTime","updateTime","must_keywords","highweight_keywords"`
- if kws != "" {
- var qstr = tools.DSL4SearchByKwsOrid(kws, id, repositoryIdArr)
- link_obj = elastic.GetAllByNgram(INDEX, TYPE, qstr, "", "", search_field, 0, 5, 0, false)
- //log.Println("link_obj:", link_obj)
- } else {
- }
- obj := []interface{}{}
- obj = append(obj, kws)
- obj = append(obj, link_obj)
- context.JSON(http.StatusOK, obj)*/
- return &knowledgeclient.RecommendAnswerResp{}, nil
- }
|