1、如果输入的名字和库中的名字完全匹配就精确搜索
2、如果输入的名字在内容中有包含信息 就进行模糊匹配
3、如果搜索没有结果,将名字转化成拼音进行搜索
4、如果拼音搜索都没,那么要进行分词了猜测
/** * 精确搜索还是模糊搜索 * 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) { $rs = BuyModel::instance ()->getGoodsLikeTitle ( $title ); if (empty ( $rs )) { $py = Pinyin::utf8_to ( $title, true ); $rs = BuyModel::instance ()->getGoodsLikePinyin ( $py ); } $goods = $this->parseGoodsStatus ( $rs ); return $this->getGoodsImageBySKU ( $goods ); }