1、如果输入的名字和库中的名字完全匹配就精确搜索
2、如果输入的名字在内容中有包含信息 就进行模糊匹配
3、如果搜索没有结果,将名字转化成拼音进行搜索
/** * 精确搜索还是模糊搜索 * Enter description here ... * @param string $title * @return array 1精确 2模糊 */ public function search($title) { if (empty ( $title )) { return; } $title = urldecode ( $title ); $goods = $this->getGoodsByName ( $title ); if (! empty ( $goods )) { $rs = $this->getGoodsMXBySKU ( $goods [‘sku‘] ); return array (‘status‘ => 1, ‘data‘ => $rs ); } $rs = $this->getGoodsLikeTitle ( $title ); return array (‘status‘ => 2, ‘data‘ => $rs ); } private function getGoodsLikeTitle($title) { $py = Pinyin::utf8_to ( $title, true ); if (!strpos ( $title, "_" )) { $rs = BuyModel::instance ()->getGoodsLikePinyin ( $py ); } else { $rs = BuyModel::instance ()->getGoodsLikeTitle ( $title ); } $goods = $this->parseGoodsStatus ( $rs ); return $this->getGoodsImageBySKU ( $goods ); }
时间: 2024-12-15 14:00:28