panix / mod-zend-search
Zend Lucene 搜索
dev-main
2021-12-05 16:44 UTC
Requires
- yiisoft/yii2: *
- zendframework/zendsearch: *@RC
This package is auto-updated.
Last update: 2024-09-05 22:27:25 UTC
README
Zend Lucene 搜索
安装
安装此扩展的首选方式是通过 composer。
- 添加
"panix/mod-zend-search" : "*", "zendframework/zendsearch": "2.0.0rc6"
到您应用程序的 composer.json
文件的 require 部分。
- 在您应用程序配置文件的
components
部分添加一个新组件,例如
'components' => [ 'search' => [ 'class' => 'panix\mod\search\Search', 'models' => [ 'app\modules\page\models\Page', ], ], // ... ],
- 在 AR 模型中添加行为,例如
use panix\mod\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], ]; } ], ]; }