Authored by 周少峰

搜索词高亮

@@ -169,6 +169,7 @@ class HelperSearch @@ -169,6 +169,7 @@ class HelperSearch
169 169
170 $gender = isset(self::$options['gender']) ? explode(',', self::$options['gender'])[0] : 0; 170 $gender = isset(self::$options['gender']) ? explode(',', self::$options['gender'])[0] : 0;
171 foreach($val['goods_list'] as $k => $v){ 171 foreach($val['goods_list'] as $k => $v){
  172 +
172 $goods_list[$k]['url'] = Helpers::getUrlBySkc($val['product_id'], $v['goods_id'], $val['cn_alphabet']); 173 $goods_list[$k]['url'] = Helpers::getUrlBySkc($val['product_id'], $v['goods_id'], $val['cn_alphabet']);
173 //女封 174 //女封
174 if (isset($v['cover_1']) && $gender == 1) { 175 if (isset($v['cover_1']) && $gender == 1) {
@@ -187,7 +188,15 @@ class HelperSearch @@ -187,7 +188,15 @@ class HelperSearch
187 if (!empty($val['default_images'])) { 188 if (!empty($val['default_images'])) {
188 $val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]); 189 $val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]);
189 } 190 }
190 - 191 + //搜索关键字高亮
  192 + $patten = "/".self::$params['query']."/i";
  193 + if (isset(self::$params['query']) && !empty(self::$params['query']) && preg_match($patten, $val['product_name'], $match)) {
  194 + foreach ($match as $k => &$v) {
  195 + $replace[$k] = '<span style="color: #cc0000">'.$v.'</span>';
  196 + $v = '/'.$v.'/';
  197 + }
  198 + $val['product_name'] = preg_replace($match, $replace, $val['product_name']);
  199 + }
191 $good = array( 200 $good = array(
192 'tags' => array( 201 'tags' => array(
193 'isNew' => $isNew, 202 'isNew' => $isNew,