作者 李宇航

合并分支 'lyh-server' 到 'master'

GXgeo设置



查看合并请求 !2337
@@ -85,7 +85,6 @@ class GeoQuestionRes extends Command @@ -85,7 +85,6 @@ class GeoQuestionRes extends Command
85 continue; 85 continue;
86 } 86 }
87 if ($platform == 'Google AI Overview') { 87 if ($platform == 'Google AI Overview') {
88 - continue;  
89 // overview 数据结构不确定, 需要单独处理数据 88 // overview 数据结构不确定, 需要单独处理数据
90 $data = $geo_service->getGooglePlatformResult($question); 89 $data = $geo_service->getGooglePlatformResult($question);
91 $result = $this->dealGoogleData($data); 90 $result = $this->dealGoogleData($data);
@@ -106,21 +105,18 @@ class GeoQuestionRes extends Command @@ -106,21 +105,18 @@ class GeoQuestionRes extends Command
106 $title = array_column(array_column($result['annotations'], 'url_citation'), 'title');; 105 $title = array_column(array_column($result['annotations'], 'url_citation'), 'title');;
107 $hit_data = array_merge($url, $title, $hit_data); 106 $hit_data = array_merge($url, $title, $hit_data);
108 } 107 }
109 - $hit_string = implode(',', $hit_data);  
110 // 命中关键词和路由 108 // 命中关键词和路由
111 $hit_keyword = $hit_url = []; 109 $hit_keyword = $hit_url = [];
112 $hit = 0; 110 $hit = 0;
113 if (!empty($taskInfo['keywords'])) { 111 if (!empty($taskInfo['keywords'])) {
114 - $pattern = '/(' . implode('|', array_map('preg_quote', $taskInfo['keywords'])) . ')/i';  
115 - if (preg_match($pattern, $hit_string, $matches)) {  
116 - $hit_keyword = $matches[0]; 112 + $hit_keyword = $this->getKeywords($taskInfo['keywords'],$hit_data);
  113 + if (!empty($hit_keyword)) {
117 $hit++; 114 $hit++;
118 } 115 }
119 } 116 }
120 if (!empty($taskInfo['url'])) { 117 if (!empty($taskInfo['url'])) {
121 - $pattern = '/(' . implode('|', array_map('preg_quote', $taskInfo['url'])) . ')/i';  
122 - if (preg_match($pattern, $hit_string, $matches)) {  
123 - $hit_url = $matches[0]; 118 + $hit_url = $this->getUrl($taskInfo['url'],$hit_data);
  119 + if (!empty($hit_url)) {
124 $hit++; 120 $hit++;
125 } 121 }
126 } 122 }
@@ -154,6 +150,46 @@ class GeoQuestionRes extends Command @@ -154,6 +150,46 @@ class GeoQuestionRes extends Command
154 } 150 }
155 151
156 /** 152 /**
  153 + * @remark :获取命中的url
  154 + * @name :getUrl
  155 + * @author :lyh
  156 + * @method :post
  157 + * @time :2025/7/3 16:38
  158 + */
  159 + public function getUrl($urlArr = [],$result_annotations = []){
  160 + $url = [];
  161 + if(!empty($urlArr)){
  162 + $str = implode(',',$result_annotations);
  163 + foreach ($urlArr as $u_item){
  164 + if (str_contains($str, $u_item)) {
  165 + $url[] = $u_item;
  166 + }
  167 + }
  168 + }
  169 + return array_values(array_unique($url));
  170 + }
  171 +
  172 + /**
  173 + * @remark :获取命中的关键词
  174 + * @name :getKeywords
  175 + * @author :lyh
  176 + * @method :post
  177 + * @time :2025/7/3 16:26
  178 + */
  179 + public function getKeywords($keywordArr = [],$result_text = []){
  180 + $keywords = [];
  181 + if(!empty($keywordArr) && !empty($result_text)){
  182 + $str = implode(',',$result_text);
  183 + foreach ($keywordArr as $k_item){
  184 + if (str_contains($str, $k_item)) {
  185 + $keywords[] = $k_item;
  186 + }
  187 + }
  188 + }
  189 + return $keywords;
  190 + }
  191 +
  192 + /**
157 * 整合Google平台数据 193 * 整合Google平台数据
158 * @param $data 194 * @param $data
159 * @return array 195 * @return array