提交 ec664a54 编写于 作者: T Terry

搜索功能:新增sku精准搜索

上级 efbe92a1
......@@ -219,17 +219,26 @@ class MongoSearch extends Service implements SearchInterface
*/
protected function actionGetSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count)
{
$filter = [
'pageNum' => $pageNum,
'numPerPage' => $numPerPage,
'where' => $where,
'product_search_max_count' => $product_search_max_count,
'select' => $select,
];
//var_dump($filter);exit;
$collection = $this->fullTearchText($filter);
// 先进行sku搜索,如果有结果,说明是针对sku的搜索
$searchText = $where['$text']['$search'];
$productM = Yii::$service->product->getBySku($searchText);
if ($productM) {
$collection['coll'][] = $productM;
$collection['count'] = 1;
} else {
$filter = [
'pageNum' => $pageNum,
'numPerPage' => $numPerPage,
'where' => $where,
'product_search_max_count' => $product_search_max_count,
'select' => $select,
];
//var_dump($filter);exit;
$collection = $this->fullTearchText($filter);
}
$collection['coll'] = Yii::$service->category->product->convertToCategoryInfo($collection['coll']);
//var_dump($collection);
return $collection;
}
......
......@@ -132,44 +132,52 @@ class XunSearch extends Service implements SearchInterface
protected function fullTearchText($select, $where, $pageNum, $numPerPage, $product_search_max_count)
{
$XunSearchQuery = $this->_searchModel->find()->asArray();
$XunSearchQuery->fuzzy($this->fuzzy);
$XunSearchQuery->synonyms($this->synonyms);
if (is_array($where) && !empty($where)) {
if (isset($where['$text']['$search']) && $where['$text']['$search']) {
$XunSearchQuery->where($where['$text']['$search']);
} else {
return [];
$searchText = $where['$text']['$search'];
$productM = Yii::$service->product->getBySku($searchText);
$productIds = [];
if ($productM) {
$productIds[] = $productM['_id'];
} else {
$XunSearchQuery = $this->_searchModel->find()->asArray();
$XunSearchQuery->fuzzy($this->fuzzy);
$XunSearchQuery->synonyms($this->synonyms);
if (is_array($where) && !empty($where)) {
if (isset($where['$text']['$search']) && $where['$text']['$search']) {
$XunSearchQuery->where($where['$text']['$search']);
} else {
return [];
}
foreach ($where as $k => $v) {
if ($k != '$text') {
$XunSearchQuery->andWhere([$k => $v]);
}
}
}
foreach ($where as $k => $v) {
if ($k != '$text') {
$XunSearchQuery->andWhere([$k => $v]);
$XunSearchQuery->orderBy(['score' => SORT_DESC]);
$XunSearchQuery->limit($product_search_max_count);
$XunSearchQuery->offset(0);
$search_data = $XunSearchQuery->all();
$data = [];
foreach ($search_data as $one) {
if (!isset($data[$one['spu']])) {
$data[$one['spu']] = $one;
}
}
}
$XunSearchQuery->orderBy(['score' => SORT_DESC]);
$XunSearchQuery->limit($product_search_max_count);
$XunSearchQuery->offset(0);
$search_data = $XunSearchQuery->all();
$data = [];
foreach ($search_data as $one) {
if (!isset($data[$one['spu']])) {
$data[$one['spu']] = $one;
$count = count($data);
$offset = ($pageNum - 1) * $numPerPage;
$limit = $numPerPage;
$productIds = [];
foreach ($data as $d) {
$productIds[] = new \MongoDB\BSON\ObjectId($d['_id']);
}
}
$count = count($data);
$offset = ($pageNum - 1) * $numPerPage;
$limit = $numPerPage;
$productIds = [];
foreach ($data as $d) {
$productIds[] = new \MongoDB\BSON\ObjectId($d['_id']);
$productIds = array_slice($productIds, $offset, $limit);
}
$productIds = array_slice($productIds, $offset, $limit);
if (!empty($productIds)) {
$query = $this->_productModel->find()->asArray()
->select($select)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册