wdmg/yii2-search

站点搜索

安装: 517

依赖项: 1

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 1

开放问题: 0

类型:yii2-extension

2.0.0 2023-06-25 19:04 UTC

This package is auto-updated.

Last update: 2024-09-25 21:56:07 UTC


README

Yii2 Downloads Packagist Version Progress GitHub license

Yii2 Search module

Yii2 搜索

Yii2 的搜索模块。

该模块通过形态学(phpMorphy)或Porter的词干算法(LinguaStem)实现索引搜索。还提供了根据数据模型进行实时全文搜索的功能。

此模块是 Butterfly.СMS 内容管理系统的一个组成部分,但也可以作为一个独立的扩展使用。

版权所有 (c) 2019-2023 W.D.M.Group, Ukraine

要求

安装

要安装模块,请在控制台运行以下命令

$ composer require "wdmg/yii2-search"

配置数据库连接后,在控制台运行以下命令

$ php yii search/init

然后选择您要执行的操作

  1. 应用所有模块迁移
  2. 撤销所有模块迁移

迁移

在任何情况下,您都可以通过在控制台运行以下命令来执行迁移并创建初始数据

$ 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 - 更新依赖项