EsOrganization.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\controller;
  3. use think\facade\Log;
  4. use think\facade\Request;
  5. class EsOrganization extends CommonEsController
  6. {
  7. public function detail()
  8. {
  9. $organization = Request::param('organization') ?? '';
  10. if( ! $organization) {
  11. return $this->_json_error('参数请求有误!');
  12. }
  13. return $this->_json_succ(
  14. $this->organizationDetail($organization)
  15. );
  16. }
  17. /**
  18. * 机构分析详情
  19. */
  20. protected function organizationDetail($org)
  21. {
  22. $params = [
  23. 'index' => $this->currentLanguage() ,
  24. 'body' => [
  25. 'size' => 0,
  26. 'query' => [
  27. 'bool' => [
  28. 'filter' => [
  29. 'term' => [
  30. 'organization_parsed.keyword' => $org
  31. ]
  32. ]
  33. ]
  34. ] ,
  35. 'aggs' => [
  36. 'citedTotalCnt' => [
  37. 'sum' => [
  38. 'field' => 'citation_relate_count'
  39. ]
  40. ] ,
  41. 'docStat' => [
  42. 'terms' => [
  43. 'field' => 'year' ,
  44. 'order' => [
  45. '_key' => 'asc'
  46. ] ,
  47. 'size' => 20
  48. ] ,
  49. 'aggs' => [
  50. 'citedPerYearCnt' => [
  51. 'sum' => [
  52. 'field' => 'citation_relate_count'
  53. ]
  54. ]
  55. ]
  56. ] ,
  57. 'topKeywords' => [
  58. 'terms' => [
  59. 'field' => 'keyword_list.keyword' ,
  60. 'order' => [
  61. '_count' => 'desc'
  62. ],
  63. 'size' => 20
  64. ]
  65. ] ,
  66. 'topAlbum' => [
  67. 'terms' => [
  68. 'field' => 'album_list.keyword' ,
  69. 'order' => [
  70. '_count' => 'desc'
  71. ] ,
  72. 'size' => 20
  73. ]
  74. ]
  75. ]
  76. ]
  77. ];
  78. $client = $this->getEsClient();
  79. $result = $client->search($params);
  80. $newCitedTrend = [];
  81. $citedTrend = $result['aggregations']['docStat']['buckets'];
  82. foreach($citedTrend as $key => $value) {
  83. $newCitedTrend[$key]['key'] = $value['key'];
  84. $newCitedTrend[$key]['doc_count'] = $value['citedPerYearCnt']['value'];
  85. }
  86. $organizationDetail = [
  87. 'achievement_num' => $result['hits']['total'] ,
  88. 'citation_frequency' => $result['aggregations']['citedTotalCnt']['value'] ,
  89. 'post_trend' => $result['aggregations']['docStat']['buckets'] ,
  90. 'cited_trend' => $newCitedTrend ,
  91. 'research_topic' => $result['aggregations']['topKeywords']['buckets'] ,
  92. 'top_album' => $result['aggregations']['topAlbum']['buckets']
  93. ];
  94. return $organizationDetail;
  95. }
  96. }