Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
26592a49
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
26592a49
编写于
9月 24, 2019
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mysql search services
上级
535f58bc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
56 deletion
+22
-56
services/search/MysqlSearch.php
services/search/MysqlSearch.php
+22
-56
未找到文件。
services/search/MysqlSearch.php
浏览文件 @
26592a49
...
...
@@ -299,49 +299,32 @@ class MysqlSearch extends Service implements SearchInterface
$pageNum
=
$filter
[
'pageNum'
];
$numPerPage
=
$filter
[
'numPerPage'
];
$orderBy
=
$filter
[
'orderBy'
];
$searchM
=
$this
->
_searchModel
->
find
()
->
asArray
()
->
where
(
$whereArr
)
;
if
(
$orderBy
)
{
$searchM
->
orderBy
(
$orderBy
);
}
$search_data
=
$searchM
->
limit
(
$numPerPage
)
->
offset
((
$pageNum
-
1
)
*
$numPerPage
)
->
all
();
//var_dump($search_data);exit;
//var_dump($search_data);exit;
/**
* 在搜索页面, spu相同的sku,是否只显示其中score高的sku,其他的sku隐藏
* 如果设置为true,那么在搜索结果页面,spu相同,sku不同的产品,只会显示score最高的那个产品
* 如果设置为false,那么在搜索结果页面,所有的sku都显示。
* 这里做设置的好处,譬如服装,一个spu的不同颜色尺码可能几十个产品,都显示出来会占用很多的位置,对于这种产品您可以选择设置true
* 这个针对的京东模式的产品
*/
$data
=
[];
$count
=
0
;
$searchM
=
$this
->
_searchModel
->
find
()
->
asArray
()
->
where
(
$whereArr
);
if
(
Yii
::
$service
->
search
->
productSpuShowOnlyOneSku
)
{
foreach
(
$search_data
as
$one
)
{
if
(
!
isset
(
$data
[
$one
[
'spu'
]]))
{
$data
[
$one
[
'spu'
]]
=
$one
;
}
}
/**
* 如果产品spu存在多个sku(譬如同一款产品存在多个颜色尺码),但是分类页只显示一个sku,那么需要通过
* 下面的逻辑,对spu进行group,对score倒序,取score最大的那个sku作为分类列表显示
*/
$orderBy
[
'score'
]
=
SORT_DESC
;
$query
=
$searchM
->
orderBy
(
$orderBy
)
->
groupBy
(
'spu'
)
->
limit
(
$numPerPage
)
->
offset
((
$pageNum
-
1
)
*
$numPerPage
);
$search_data
=
$query
->
all
();
$count
=
$query
->
limit
(
null
)
->
offset
(
null
)
->
count
();
}
else
{
$data
=
$search_data
;
}
$count
=
count
(
$data
);
$offset
=
(
$pageNum
-
1
)
*
$numPerPage
;
$limit
=
$numPerPage
;
if
(
$orderBy
)
{
$searchM
->
orderBy
(
$orderBy
);
}
$query
=
$searchM
->
limit
(
$numPerPage
)
->
offset
((
$pageNum
-
1
)
*
$numPerPage
);
$search_data
=
$query
->
all
();
$count
=
$query
->
limit
(
null
)
->
offset
(
null
)
->
count
();
}
$productIds
=
[];
foreach
(
$data
as
$d
)
{
foreach
(
$
search_
data
as
$d
)
{
$productIds
[]
=
$d
[
'product_id'
];
}
$productIds
=
array_slice
(
$productIds
,
$offset
,
$limit
);
// 通过productIds数组 得到产品数据
$productPrimaryKey
=
Yii
::
$service
->
product
->
getPrimaryKey
();
if
(
!
empty
(
$productIds
))
{
//
foreach
(
$select
as
$sk
=>
$se
)
{
if
(
$se
==
'product_id'
)
{
unset
(
$select
[
$sk
]);
...
...
@@ -355,31 +338,14 @@ class MysqlSearch extends Service implements SearchInterface
],
];
$collData
=
Yii
::
$service
->
product
->
coll
(
$filter
);
$data
=
$collData
[
'coll'
];
/**
* 下面的代码的作用:将结果按照上面in查询的顺序进行数组的排序,使结果和上面的搜索结果排序一致(_id)。
*/
//var_dump($data);exit;
$s_data
=
[];
foreach
(
$data
as
$one
)
{
if
(
$one
[
$productPrimaryKey
])
{
$_id
=
(
string
)
$one
[
$productPrimaryKey
];
$s_data
[
$_id
]
=
$one
;
}
}
$return_data
=
[];
foreach
(
$productIds
as
$product_id
)
{
$pid
=
(
string
)
$product_id
;
if
(
isset
(
$s_data
[
$pid
])
&&
$s_data
[
$pid
])
{
$return_data
[]
=
$s_data
[
$pid
];
}
}
$return_data
=
$collData
[
'coll'
];
return
[
'coll'
=>
$return_data
,
'count'
=>
$count
,
];
}
return
[];
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录