recommendanswerlogic.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package logic
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/logx"
  5. "knowledgeBase/rpc/knowledge/internal/svc"
  6. "knowledgeBase/rpc/knowledge/knowledgeclient"
  7. )
  8. type RecommendAnswerLogic struct {
  9. ctx context.Context
  10. svcCtx *svc.ServiceContext
  11. logx.Logger
  12. }
  13. func NewRecommendAnswerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecommendAnswerLogic {
  14. return &RecommendAnswerLogic{
  15. ctx: ctx,
  16. svcCtx: svcCtx,
  17. Logger: logx.WithContext(ctx),
  18. }
  19. }
  20. func (l *RecommendAnswerLogic) RecommendAnswer(in *knowledgeclient.FindAnswerReq) (*knowledgeclient.RecommendAnswerResp, error) {
  21. // todo: add your logic here and delete this line
  22. /*question := in.Question
  23. result := utils.HttpDo(in.Question)
  24. var resmap []map[string]interface{}
  25. json.Unmarshal([]byte(result), &resmap)
  26. pid := utils.BsonIdToSId(res["pid"])
  27. //log.Println(pid)
  28. rquery := map[string]interface{}{
  29. "platFormUserId": pid,
  30. }
  31. repository := repositoryService.FindByField(rquery)
  32. repositoryId := utils.BsonIdToSId(repository.Id)
  33. repositoryIdArr := getCiteRepository(pid)
  34. var strr string
  35. if len(repositoryIdArr) > 0 {
  36. strr = "," + "\"" + repositoryId + "\""
  37. } else {
  38. strr = "\"" + repositoryId + "\""
  39. }
  40. repositoryIdArr = append(repositoryIdArr, strr)
  41. var kws = ""
  42. var link_obj = &[]map[string]interface{}{}
  43. if len(resmap) > 0 {
  44. for k, v := range resmap {
  45. if strings.Contains(v["nature"].(string), "n") && len(v["word"].(string)) > 3 {
  46. if k > 0 && len(kws) > 1 {
  47. kws += " "
  48. }
  49. kws += v["word"].(string)
  50. }
  51. }
  52. }
  53. //fmt.Println("关键字:", kws)
  54. var search_field = `"_id","knowledgeKeyWords","answer","relativeKnowledgeId","createUser","tags","questions","repositoryId","createTime","updateTime","must_keywords","highweight_keywords"`
  55. if kws != "" {
  56. var qstr = tools.DSL4SearchByKwsOrid(kws, id, repositoryIdArr)
  57. link_obj = elastic.GetAllByNgram(INDEX, TYPE, qstr, "", "", search_field, 0, 5, 0, false)
  58. //log.Println("link_obj:", link_obj)
  59. } else {
  60. }
  61. obj := []interface{}{}
  62. obj = append(obj, kws)
  63. obj = append(obj, link_obj)
  64. context.JSON(http.StatusOK, obj)*/
  65. return &knowledgeclient.RecommendAnswerResp{}, nil
  66. }