Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
104cd7ab
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
18
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,发现更多精彩内容 >>
提交
104cd7ab
编写于
9月 26, 2016
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fecshop product chinese language search by xunsearch
上级
02aa5fab
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
182 addition
and
6 deletion
+182
-6
app/appfront/modules/Catalogsearch/controllers/IndexController.php
...ont/modules/Catalogsearch/controllers/IndexController.php
+30
-1
config/xunsearch/search.ini
config/xunsearch/search.ini
+79
-0
models/xunsearch/Search.php
models/xunsearch/Search.php
+22
-0
services/helper/AR.php
services/helper/AR.php
+6
-2
services/search/MongoSearch.php
services/search/MongoSearch.php
+7
-0
services/search/XunSearch.php
services/search/XunSearch.php
+38
-3
未找到文件。
app/appfront/modules/Catalogsearch/controllers/IndexController.php
浏览文件 @
104cd7ab
...
...
@@ -11,6 +11,7 @@ use Yii;
use
fec\helpers\CModule
;
use
fec\helpers\CRequest
;
use
fecshop\app\appfront\modules\AppfrontController
;
use
fecshop\models\xunsearch\Search
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
...
...
@@ -20,9 +21,37 @@ class IndexController extends AppfrontController
public
function
init
(){
parent
::
init
();
}
#
վϢ
#
网站信息管理
public
function
actionIndex
()
{
/*
$model = new Search;
$model->pid = 341234;
$model->name = '小米手机';
$model->description = '小米手机Air采用了全尺寸的背光键盘,在接口方面拥有不错的扩展性。因为采用了无logo设计,小米官方会推出名画以及当代艺术家的画作的贴纸,还推出了笔记本包。';
$model->save();
$model = new Search;
$model->pid = 44444;
$model->name = '北京小米科技有限责任公司';
$model->description = '北京小米科技有限责任公司成立2010年4月,是一家专注于智能硬件和电子产品研发的移动互联网公司。“为发烧而生”是小米的产品概念。小米公司首创了用互联网模式开发手机操作系统、发烧友参与开发改进的模式。
2014年12月14日晚,美的集团发出公告称,已与小米科技签署战略合作协议,小米12.7亿元入股美的集团。2015年9月22日,小米在北京发布了新品小米4c,这款新品由小米4i升级而来,配备5英寸显示屏,搭载骁龙808处理器,号称安卓小王子。
2016年7月27日的发布会上小米笔记本终于正式亮相,这款产品叫做小米笔记本Air。';
$model->save();
*/
echo
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
;
$query
=
Search
::
find
();
$condition
=
'小米手机'
;
$data
=
$query
->
asArray
()
->
limit
(
100
)
//->where($condition)
->
all
();
foreach
(
$data
as
$d
){
var_dump
(
$d
);
echo
'<br>####################<br>'
;
}
exit
;
/*
Yii::$service->search->initFullSearchIndex();
$filter['select'] = ['_id'];
...
...
config/xunsearch/search.ini
0 → 100644
浏览文件 @
104cd7ab
project.name
=
search
project.default_charset
=
UTF-8
;服务端用默认值
;server.index = 8383
;server.search = 8384
[_id]
type
=
id
[name]
type
=
title
[description]
type
=
body
[sku]
type
=
string
index
=
mixed
[spu]
type
=
string
index
=
mixed
[score]
type
=
numeric
index
=
none
[url_key]
type
=
string
index
=
none
[price]
type
=
numeric
index
=
none
[cost_price]
type
=
numeric
index
=
none
[special_price]
type
=
numeric
index
=
none
[special_from]
type
=
numeric
index
=
none
[special_to]
type
=
numeric
index
=
none
[final_price]
type
=
numeric
index
=
none
[image]
type
=
string
index
=
none
[short_description]
type
=
string
index
=
none
[created_at]
type
=
numeric
index
=
none
[sync_updated_at]
type
=
numeric
index
=
none
[color]
type
=
string
index
=
none
[size]
type
=
string
index
=
none
\ No newline at end of file
models/xunsearch/Search.php
0 → 100644
浏览文件 @
104cd7ab
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\models\xunsearch
;
use
Yii
;
use
yii\db\ActiveRecord
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
Search
extends
\
hightman\xunsearch\ActiveRecord
{
public
static
function
projectName
()
{
return
'search'
;
// ⽫ʹ @app/config/another_name.ini ΪĿ
}
}
\ No newline at end of file
services/helper/AR.php
浏览文件 @
104cd7ab
...
...
@@ -71,7 +71,7 @@ class AR extends Service
}
public
function
save
(
$model
,
$one
){
public
function
save
(
$model
,
$one
,
$serialize
=
false
){
if
(
!
$model
){
Yii
::
$service
->
helper
->
errors
->
add
(
'ActiveRecord Save Error: $model is empty'
);
return
;
...
...
@@ -80,7 +80,11 @@ class AR extends Service
if
(
is_array
(
$attributes
)
&&
!
empty
(
$attributes
)){
foreach
(
$attributes
as
$attr
){
if
(
isset
(
$one
[
$attr
])){
$model
[
$attr
]
=
$one
[
$attr
];
if
(
$serialize
&&
is_array
(
$one
[
$attr
])){
$model
[
$attr
]
=
serialize
(
$one
[
$attr
]);
}
else
{
$model
[
$attr
]
=
$one
[
$attr
];
}
}
}
return
$model
->
save
();
...
...
services/search/MongoSearch.php
浏览文件 @
104cd7ab
...
...
@@ -145,9 +145,16 @@ class MongoSearch extends Service implements SearchInterface
if
(
!
empty
(
$this
->
searchLang
)
&&
is_array
(
$this
->
searchLang
)){
foreach
(
$this
->
searchLang
as
$langCode
=>
$mongoSearchLangName
){
Search
::
$_lang
=
$langCode
;
# 更新时间方式删除。
Search
::
deleteAll
([
'<'
,
'sync_updated_at'
,(
int
)
$nowTimeStamp
]);
# 不存在更新时间的直接删除掉。
Search
::
deleteAll
([
'sync_updated_at'
=>
[
'?exists'
=>
false
,
]
]);
}
}
...
...
services/search/XunSearch.php
浏览文件 @
104cd7ab
...
...
@@ -12,6 +12,7 @@ use yii\base\InvalidValueException;
use
yii\base\InvalidConfigException
;
use
fecshop\models\mongodb\Search
;
use
fecshop\services\Service
;
use
fecshop\models\xunsearch\Search
as
XunSearchModel
;
/**
* Search
* @author Terry Zhao <2358269014@qq.com>
...
...
@@ -25,14 +26,48 @@ class XunSearch extends Service implements SearchInterface
* 初始化xunSearch索引
*/
protected
function
actionInitFullSearchIndex
(){
return
;
}
/**
* 将产品信息同步到xunSearch引擎中
*/
protected
function
actionSyncProductInfo
(
$product_ids
,
$numPerPage
){
if
(
is_array
(
$product_ids
)
&&
!
empty
(
$product_ids
)){
$productPrimaryKey
=
Yii
::
$service
->
product
->
getPrimaryKey
();
$searchModel
=
new
Search
;
$filter
[
'select'
]
=
$searchModel
->
attributes
();
$filter
[
'asArray'
]
=
true
;
$filter
[
'where'
][]
=
[
'in'
,
$productPrimaryKey
,
$product_ids
];
$filter
[
'numPerPage'
]
=
$numPerPage
;
$filter
[
'pageNum'
]
=
1
;
$coll
=
Yii
::
$service
->
product
->
coll
(
$filter
);
if
(
is_array
(
$coll
[
'coll'
])
&&
!
empty
(
$coll
[
'coll'
])){
foreach
(
$coll
[
'coll'
]
as
$one
){
$one_name
=
$one
[
'name'
];
$one_description
=
$one
[
'description'
];
$one_short_description
=
$one
[
'short_description'
];
if
(
!
empty
(
$this
->
searchLang
)
&&
is_array
(
$this
->
searchLang
)){
foreach
(
$this
->
searchLang
as
$langCode
){
$XunSearchModel
=
new
XunSearchModel
();
$XunSearchModel
->
_id
=
$one
[
'_id'
]
->
{
'$id'
};
$one
[
'name'
]
=
Yii
::
$service
->
fecshoplang
->
getLangAttrVal
(
$one_name
,
'name'
,
$langCode
);
$one
[
'description'
]
=
Yii
::
$service
->
fecshoplang
->
getLangAttrVal
(
$one_description
,
'description'
,
$langCode
);
$one
[
'short_description'
]
=
Yii
::
$service
->
fecshoplang
->
getLangAttrVal
(
$one_short_description
,
'short_description'
,
$langCode
);
$one
[
'sync_updated_at'
]
=
time
();
$serialize
=
true
;
Yii
::
$service
->
helper
->
ar
->
save
(
$XunSearchModel
,
$one
,
$serialize
);
if
(
$errors
=
Yii
::
$service
->
helper
->
errors
->
get
()){
# 报错。
echo
$errors
;
//return false;
}
}
}
}
}
}
return
true
;
}
/**
* 批量更新过程中,被更新的产品都会更新字段sync_updated_at
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录