合并分支 'lyh-server' 到 'master'
gx 查看合并请求 !2339
正在显示
1 个修改的文件
包含
36 行增加
和
30 行删除
| @@ -81,9 +81,11 @@ class GeoQuestionRes extends Command | @@ -81,9 +81,11 @@ class GeoQuestionRes extends Command | ||
| 81 | GET_RESULT: | 81 | GET_RESULT: |
| 82 | $error_num++; | 82 | $error_num++; |
| 83 | try { | 83 | try { |
| 84 | + echo '执行次数:'.$error_num.PHP_EOL; | ||
| 84 | if ($error_num >= 5) { | 85 | if ($error_num >= 5) { |
| 85 | continue; | 86 | continue; |
| 86 | } | 87 | } |
| 88 | + echo '执行平台:'.$platform.PHP_EOL; | ||
| 87 | if ($platform == 'Google AI Overview') { | 89 | if ($platform == 'Google AI Overview') { |
| 88 | // overview 数据结构不确定, 需要单独处理数据 | 90 | // overview 数据结构不确定, 需要单独处理数据 |
| 89 | $data = $geo_service->getGooglePlatformResult($question); | 91 | $data = $geo_service->getGooglePlatformResult($question); |
| @@ -201,42 +203,46 @@ class GeoQuestionRes extends Command | @@ -201,42 +203,46 @@ class GeoQuestionRes extends Command | ||
| 201 | 'model' => 'Google AI Overview', | 203 | 'model' => 'Google AI Overview', |
| 202 | 'text' => '', | 204 | 'text' => '', |
| 203 | ]; | 205 | ]; |
| 204 | - if (FALSE == empty($data['ai_overview']['texts']) && is_array($data['ai_overview']['texts'])) { | 206 | + if(!empty($data['data']['text_parts']) && is_array($data['data']['text_parts'])){ |
| 205 | $texts = []; | 207 | $texts = []; |
| 206 | - foreach ($data['ai_overview']['texts'] as $item) { | ||
| 207 | - // 提取链接 | ||
| 208 | - if (FALSE == empty($item['links'])) { | ||
| 209 | - foreach ($item['links'] as $link) { | ||
| 210 | - if (FALSE == empty($link['text']) && FALSE == empty($link['link'])) { | ||
| 211 | - $result['annotations'][] = [ | ||
| 212 | - 'type' => 'url_citation', | ||
| 213 | - 'url_citation' => [ | ||
| 214 | - 'url' => $link['link'], | ||
| 215 | - 'title' => $link['text'] | ||
| 216 | - ], | ||
| 217 | - ]; | ||
| 218 | - } | ||
| 219 | - } | 208 | + foreach ($$data['data']['text_parts'] as $item){ |
| 209 | + if(empty($item['text'])){ | ||
| 210 | + continue; | ||
| 220 | } | 211 | } |
| 221 | - // 第一层就有内容 | ||
| 222 | - if (FALSE == empty($item['snippet'])) { | ||
| 223 | - // title 放到数组最前面 | ||
| 224 | - if (FALSE == empty($item['type']) && $item['type'] == 'title') | ||
| 225 | - array_unshift($texts, $item['snippet']); | ||
| 226 | - else | ||
| 227 | - array_push($texts, $item['snippet']); | 212 | + switch ($item['type']){ |
| 213 | + case 'paragraph': | ||
| 214 | + array_push($texts, $item['text']); | ||
| 215 | + break; | ||
| 216 | + case 'title': | ||
| 217 | + array_unshift($texts, $item['text']); | ||
| 218 | + break; | ||
| 219 | + case 'list': | ||
| 220 | + if(!empty($item['list'])){ | ||
| 221 | + foreach ($item['list'] as $sonItem){ | ||
| 222 | + array_push($texts, $sonItem['title']); | ||
| 223 | + array_push($texts, $sonItem['text']); | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + default: | ||
| 227 | + break; | ||
| 228 | } | 228 | } |
| 229 | - // list类型 | ||
| 230 | - if (FALSE == empty($item['type']) && $item['type'] == 'list' && FALSE == empty($item['list']) && is_array($item['list'])) { | ||
| 231 | - foreach ($item['list'] as $list) { | ||
| 232 | - if (FALSE == empty($list['snippet'])) | ||
| 233 | - array_push($texts, $list['snippet']); | ||
| 234 | - } | 229 | + } |
| 230 | + } | ||
| 231 | + if(!empty($data['data']['reference_links']) && is_array($data['data']['reference_links'])){ | ||
| 232 | + foreach ($data['data']['reference_links'] as $link) { | ||
| 233 | + if (!empty($link['text']) && !empty($link['link'])) { | ||
| 234 | + $result['annotations'][] = [ | ||
| 235 | + 'type' => 'url_citation', | ||
| 236 | + 'url_citation' => [ | ||
| 237 | + 'url' => $link['link'], | ||
| 238 | + 'title' => $link['title'] | ||
| 239 | + ], | ||
| 240 | + ]; | ||
| 235 | } | 241 | } |
| 236 | } | 242 | } |
| 237 | - $text = implode(PHP_EOL, $texts); | ||
| 238 | - $result['text'] = $text; | ||
| 239 | } | 243 | } |
| 244 | + $text = implode(PHP_EOL, $texts); | ||
| 245 | + $result['text'] = $text; | ||
| 240 | return $result; | 246 | return $result; |
| 241 | } | 247 | } |
| 242 | 248 |
-
请 注册 或 登录 后发表评论