korotovsky / elasticsearch
该包已被弃用且不再维护。未建议替代包。
基于 yii 项目的 Elastic 搜索模块
dev-master
2013-04-27 16:31 UTC
Requires
- yiisoft/yii: dev-master
This package is not auto-updated.
Last update: 2015-09-06 07:47:04 UTC
README
这是一个基于 https://github.com/phpnode/YiiBlocks/tree/master/elasticSearch 的项目
代码针对 PHP 5.4, Yii 1.1.13 和 ElasticSearch 版本 0.18.2 优化
此分支目前不稳定
安装
在您的 composer.json 文件中添加以下行
"require":{
"korotovsky/elasticsearch": "dev-master"
}
配置模块
如果模块没有父模块,请将其添加到您的配置文件中
'modules' => array(
// other modules...
'elasticsearch' => array(
'class' => 'korotovsky\elasticsearch\ElasticSearchModule', // Define class
'accessCallback' => function() { // Define access callback, if true, then user will be redirected to default login page
return Yii::app()->user->isGuest || !Yii::app()->user->checkAccess('administrator');
},
),
),
如果模块 elasticsearch 是例如 admin 模块的一部分,请将其添加到您的配置文件中
'modules' => array(
// other modules...
'elasticsearch' => array(
'class' => 'korotovsky\elasticsearch\ElasticSearchModule', // Define class
'accessCallback' => function() { // Define access callback, if true, then user will be redirected to default login page
return Yii::app()->user->isGuest || !Yii::app()->user->checkAccess('administrator');
},
'parentModule' => 'admin', // Define parent module
'properties' => array( // List of properties for export from parent module to elasticSearch module
'menu', // e.g. menu property with admin menu
),
'layoutPath' => 'admin.views.layouts', // admin layouts path
'layout' => 'main', // layout name
),
),
模型设置
将行为添加到您的模型中
public function behaviors()
{
return array(
'elasticSearch' => array(
'class' => '\korotovsky\elasticsearch\extensions\elasticsearch\AElasticSearchable',
'indexName' => __CLASS__,
'indexAttributes' => array(
'iname',
'created',
'width',
'height',
),
'mapping' => array(
'iname' => array(
'type' => 'multi_field',
'fields' => array(
'title' => array(
'type' => 'string',
'analyzer' => 'translit',
),
'metaphone' => array(
'type' => 'string',
'analyzer' => 'translitAndMetaphone'
),
'sort' => array(
'type' => 'string',
'index' => 'not_analyzed',
),
)
),
'id' => array('type' => 'integer', 'index' => 'not_analyzed'),
'width' => array('type' => 'integer'),
'height' => array('type' => 'integer', 'index' => 'not_analyzed'),
),
)
);
}