korotovsky / elasticsearch
This package is abandoned and no longer maintained.
No replacement package was suggested.
The Elastic search module for yii projects
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
This is project based on https://github.com/phpnode/YiiBlocks/tree/master/elasticSearch
Code optimized for PHP 5.4, Yii 1.1.13 and ElasticSearch verson 0.18.2
THIS IS BRANCH CURRENTLY UNSTABLE
Install
Add to your composer.json folowing lines
"require":{
"korotovsky/elasticsearch": "dev-master"
}
Configuring module
In case if the module does not have a parent module, add to your config file:
'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');
},
),
),
In case if the module elasticsearch is a part of e.g. admin module, then add to your config file:
'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
),
),
Model setup
Add behaviour to your model:
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'),
),
)
);
}