作者 赵彬吉

update

@@ -590,11 +590,8 @@ class UpdateSeoTdk extends Command @@ -590,11 +590,8 @@ class UpdateSeoTdk extends Command
590 // 前后缀如果已经存在, 就不在拼接当前类型 590 // 前后缀如果已经存在, 就不在拼接当前类型
591 if (FALSE !== strpos($topic, $keyword)) 591 if (FALSE !== strpos($topic, $keyword))
592 return $str; 592 return $str;
593 - //处理单词复数 s es ies ves  
594 - $keyword = rtrim($keyword, 'ves');  
595 - $keyword = rtrim($keyword, 'ies');  
596 - $keyword = rtrim($keyword, 'es');  
597 - $keyword = rtrim($keyword, 's'); 593 + //复数转单数
  594 + $keyword = Str::singular($keyword);
598 595
599 $topic_words = explode(" ", $topic); 596 $topic_words = explode(" ", $topic);
600 if($type == 'prefix' && Str::startsWith($topic_words[0], $keyword)){ 597 if($type == 'prefix' && Str::startsWith($topic_words[0], $keyword)){
@@ -605,21 +602,27 @@ class UpdateSeoTdk extends Command @@ -605,21 +602,27 @@ class UpdateSeoTdk extends Command
605 } 602 }
606 } 603 }
607 } 604 }
608 - //随机取 605 + //随机取 并单复数去重
609 shuffle($fix_keyword); 606 shuffle($fix_keyword);
610 - if (count($fix_keyword) < $num)  
611 - return implode(", ", $fix_keyword);  
612 - $keyword = array_slice($fix_keyword, 0, $num);  
613 - $str = implode(", ", $keyword);  
614 -  
615 - // 前后缀内部去重  
616 - foreach ($keyword as $k=>$v){  
617 - $tmp = rtrim($v, 's');  
618 - if (substr_count($str, $tmp) > 1) {  
619 - unset($keyword[$k]);  
620 - $str = implode(", ", $keyword); 607 + $keywords = [];
  608 + foreach ($fix_keyword as $v){
  609 + if($num == 0){
  610 + break;
  611 + }
  612 + $is_repeat = false;
  613 + foreach ($keywords as $keyword){
  614 + if(Str::singular($keyword) == Str::singular($v)){
  615 + $is_repeat = true;
  616 + break;
  617 + }
  618 + }
  619 + if($is_repeat){
  620 + continue;
621 } 621 }
  622 + $keywords[] = $v;
  623 + $num--;
622 } 624 }
  625 + $str = implode(', ', $keywords);
623 } 626 }
624 return $str; 627 return $str;
625 } 628 }