wdmg / yii2-search
站点搜索
2.0.0
2023-06-25 19:04 UTC
Requires
- wdmg/lingua-stem: ^1.1.0
- wdmg/phpmorphy: ^1.3.2
- wdmg/yii2-base: ^1.2.4
- wdmg/yii2-helpers: ^1.3.2
- wdmg/yii2-selectinput: ^1.0.9
- wdmg/yii2-validators: ^1.0.6
- yiisoft/yii2: ^2.0.40
README
Yii2 搜索
Yii2 的搜索模块。
该模块通过形态学(phpMorphy)或Porter的词干算法(LinguaStem)实现索引搜索。还提供了根据数据模型进行实时全文搜索的功能。
此模块是 Butterfly.СMS 内容管理系统的一个组成部分,但也可以作为一个独立的扩展使用。
版权所有 (c) 2019-2023 W.D.M.Group, Ukraine
要求
- PHP 5.6 或更高版本
- Yii2 v.2.0.40 和最新版本
- Yii2 Base 模块(必需)
- phpMorphy 库
- LinguaStem 库
- Yii2 辅助工具
安装
要安装模块,请在控制台运行以下命令
$ composer require "wdmg/yii2-search"
配置数据库连接后,在控制台运行以下命令
$ php yii search/init
然后选择您要执行的操作
- 应用所有模块迁移
- 撤销所有模块迁移
迁移
在任何情况下,您都可以通过在控制台运行以下命令来执行迁移并创建初始数据
$ php yii migrate --migrationPath=@vendor/wdmg/yii2-search/migrations
配置
要将模块添加到项目中,请在配置文件中添加以下数据
'modules' => [
...
'search' => [ // list of supported models for live search or/and indexation
'class' => 'wdmg\search\Module',
'routePrefix' => 'admin',
'supportModels' => [
'news' => [
'class' => 'wdmg\news\models\News',
'indexing' => [
'on_insert' => true,
'on_update' => true,
'on_delete' => true
],
'options' => [
'title' => 'title', // attr name (string) of model or function($model)
'url' => 'url', // attr name (string) of model or function($model)
'fields' => [
'title',
'keywords',
'description',
'content'
],
'conditions' => [
'status' => 1
]
]
],
...
],
'cacheExpire' = 86400, // live search cache lifetime, `0` - for not use cache
'indexingOptions' = [ // indexation options
'processing' => 'phpMorphy', // Set `phpMorphy` or `LinguaStem`
'language' => 'ru-RU', // Support 'ru-RU', 'uk-UA', 'de-DE'
'analyze_by' => 'relevance',
'max_execution_time' => 0, // max execution time in sec. for indexing process
'memory_limit' => null, // max operating memory in Mb for indexing process
'max_words' => 50,
],
'analyzerOptions' = [ // text analyzer options, see \wdmg\helpers\TextAnalyzer
'min_length' => 3,
'stop_words' => [],
'weights' => []
],
'snippetOptions' = [ // build search snippet options
'max_words_before' => 6,
'max_words_after' => 4,
'bolder_tag' => 'strong',
'max_length' => 255,
'delimiter' => '…'
],
'searchAccuracy' = 90, // search accuracy
],
...
],
路由
使用模块的 Module::dashboardNavItems()
方法生成 NavBar 的导航项列表,如下所示
<?php
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'label' => 'Modules',
'items' => [
Yii::$app->getModule('search')->dashboardNavItems(),
...
]
]);
?>
状态和版本 [准备就绪]
- v.2.0.0 - 更新版权信息,修复导航菜单
- v.1.1.4 - 修复 MySQL >= 5.7 的 mysql 语法错误:1055
- v.1.1.3 - 更新依赖项