正在显示
1 个修改的文件
包含
22 行增加
和
5 行删除
| @@ -377,9 +377,26 @@ class UpdateSeoTdk extends Command | @@ -377,9 +377,26 @@ class UpdateSeoTdk extends Command | ||
| 377 | continue; | 377 | continue; |
| 378 | } | 378 | } |
| 379 | 379 | ||
| 380 | - $prefix = $this->getPrefixKeyword($project_id, 'prefix', 1, $v[$this->topic_fields[$table]]); | ||
| 381 | - $suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, $v[$this->topic_fields[$table]]); | ||
| 382 | - $seo_title = $prefix . ' ' . $v[$this->topic_fields[$table]] . ' ' . $suffix; | 380 | + $title = $v[$this->topic_fields[$table]]; |
| 381 | + | ||
| 382 | + $prefix = $this->getPrefixKeyword($project_id, 'prefix', 1, $title); | ||
| 383 | + //in,for,with,to,near,from 这些介词 只拼前缀,不拼后缀 | ||
| 384 | + $suffix_ban = ['in ', 'for ', 'with ', 'to ', 'near ','from ', 'In ', 'For ', 'With ', 'To ', 'Near ','From ']; | ||
| 385 | + $suffix = ''; | ||
| 386 | + if(Str::contains($title, $suffix_ban)){ | ||
| 387 | + // 某些后缀不能并存的情况 | ||
| 388 | + $ban_suffix = []; | ||
| 389 | + //services/service 结尾的词,后缀不拼manufacturer,factory | ||
| 390 | + if (Str::endsWith($title, ['services', 'service', 'Services', 'Service'])) { | ||
| 391 | + $ban_suffix = ['manufacturer', 'factory', 'Manufacturer', 'Factory', 'Factories', 'Manufacturers']; | ||
| 392 | + } | ||
| 393 | + //前缀有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company | ||
| 394 | + if (Str::startsWith($title, ['wholesale', 'cheap', 'Wholesale', 'Cheap'])) { | ||
| 395 | + $ban_suffix = array_merge($ban_suffix, ['manufacturer', 'factory', 'exporter', 'company', 'Manufacturer', 'Factory', 'Exporter', 'Company', 'Factories', 'Manufacturers', 'Exporters', 'Companies']); | ||
| 396 | + } | ||
| 397 | + $suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, $title, $ban_suffix); | ||
| 398 | + } | ||
| 399 | + $seo_title = $prefix . ' ' . $title . ' ' . $suffix; | ||
| 383 | } | 400 | } |
| 384 | 401 | ||
| 385 | $data[$field] = trim($seo_title); | 402 | $data[$field] = trim($seo_title); |
| @@ -548,7 +565,7 @@ class UpdateSeoTdk extends Command | @@ -548,7 +565,7 @@ class UpdateSeoTdk extends Command | ||
| 548 | * @param $num | 565 | * @param $num |
| 549 | * @return string | 566 | * @return string |
| 550 | */ | 567 | */ |
| 551 | - public function getPrefixKeyword($project_id, $type, $num, $topic='') | 568 | + public function getPrefixKeyword($project_id, $type, $num, $topic='', $ban_suffix = []) |
| 552 | { | 569 | { |
| 553 | $str = ''; | 570 | $str = ''; |
| 554 | $info = $this->getDeployOptimize($project_id); | 571 | $info = $this->getDeployOptimize($project_id); |
| @@ -579,7 +596,7 @@ class UpdateSeoTdk extends Command | @@ -579,7 +596,7 @@ class UpdateSeoTdk extends Command | ||
| 579 | //随机取 | 596 | //随机取 |
| 580 | shuffle($fix_keyword); | 597 | shuffle($fix_keyword); |
| 581 | if (count($fix_keyword) < $num) | 598 | if (count($fix_keyword) < $num) |
| 582 | - return $str; | 599 | + return implode(", ", $fix_keyword); |
| 583 | $keyword = array_slice($fix_keyword, 0, $num); | 600 | $keyword = array_slice($fix_keyword, 0, $num); |
| 584 | $str = implode(", ", $keyword); | 601 | $str = implode(", ", $keyword); |
| 585 | 602 |
-
请 注册 或 登录 后发表评论