提交 104cd7ab 编写于 作者: R root

fecshop product chinese language search by xunsearch

上级 02aa5fab
......@@ -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'];
......
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
<?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
......@@ -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();
......
......@@ -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,
]
]);
}
}
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册