himiklab/yii2-search-component-v2

This package is abandoned and no longer maintained. No replacement package was suggested.

Yii2 Zend Lucene search component v2

Installs: 17 138

Dependents: 0

Suggesters: 0

Security: 0

Stars: 25

Watchers: 4

Forks: 8

Open Issues: 1

Type:yii2-extension

2.0.7 2019-05-18 09:23 UTC

This package is auto-updated.

Last update: 2022-01-12 15:39:57 UTC


README

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