yii2-search-component-v2

  • Owner: himiklab/yii2-search-component-v2
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Yii2 Zend Lucene Search Component V2

Zend Lucene search component for Yii2.

Packagist Packagist license

Installation

The preferred way to install this extension is through composer.

  • Add
"himiklab/yii2-search-component-v2" : "*",
"zendframework/zendsearch": "2.0.0rc6"

to the require section of your application's composer.json file.

  • Add a new component in components section of your application's configuration file, for example:
'components' => [
    'search' => [
        'class' => 'himiklab\yii2\search\Search',
        'models' => [
            'app\modules\page\models\Page',
        ],
    ],
    // ...
],
  • Add behavior in the AR models, for example:
use himiklab\yii2\search\behaviors\SearchBehavior;

public function behaviors()
{
    return [
        'search' => [
            'class' => SearchBehavior::className(),
            'searchScope' => function ($model) {
                /** @var \yii\db\ActiveQuery $model */
                $model->select(['title', 'body', 'url']);
                $model->andWhere(['indexed' => true]);
            },
            'searchFields' => function ($model) {
                /** @var self $model */
                return [
                    ['name' => 'title', 'value' => $model->title],
                    ['name' => 'body', 'value' => strip_tags($model->body)],
                    ['name' => 'url', 'value' => $model->url, 'type' => SearchBehavior::FIELD_KEYWORD],
                    ['name' => 'model', 'value' => 'page', 'type' => SearchBehavior::FIELD_UNSTORED],
                ];
            }
        ],
    ];
}

Usage

See example Search module in samples directory.

Resources

Main metrics

Overview
Name With Ownerhimiklab/yii2-search-component-v2
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2014-12-03 15:55:26
Pushed At2019-05-23 06:50:36
Last Commit At2019-05-18 12:23:15
Release Count5
Last Release Name2.0.7 (Posted on )
First Release Name2.0.3 (Posted on )
用户参与
Stargazers Count25
Watchers Count4
Fork Count8
Commits Count15
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count0
Pull Requests Open Count0
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private