Skip to content
Search module for Yii2
PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
commands
controllers
messages/ru-RU/app/modules
migrations
models
views
CHANGELOG.md
LICENSE
Module.php
README.md
composer.json

README.md

Yii2 Github all releases Progress GitHub license GitHub release

Yii2 Search

Search module for Yii2.

The module implements indexed search using morphology (phpMorphy) or Porter's stemmer algorithm (LinguaStem). A live full-text search by data model is also provided.

Requirements

Installation

To install the module, run the following command in the console:

$ composer require "wdmg/yii2-search"

After configure db connection, run the following command in the console:

$ php yii search/init

And select the operation you want to perform:

  1. Apply all module migrations
  2. Revert all module migrations

Migrations

In any case, you can execute the migration and create the initial data, run the following command in the console:

$ php yii migrate --migrationPath=@vendor/wdmg/yii2-search/migrations

Configure

To add a module to the project, add the following data in your configuration file:

'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` (not support et)
           '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
    ],
    ...
],

Routing

Use the Module::dashboardNavItems() method of the module to generate a navigation items list for NavBar, like this:

<?php
    echo Nav::widget([
    'options' => ['class' => 'navbar-nav navbar-right'],
        'label' => 'Modules',
        'items' => [
            Yii::$app->getModule('search')->dashboardNavItems(),
            ...
        ]
    ]);
?>

Status and version [in progress development]

  • v.1.0.8 - Up to date dependencies, bugfix migrations
  • v.1.0.7 - Added support for Blog module
  • v.1.0.6 - Added no caching parameter for search method
  • v.1.0.5 - Added ignored patterns, URL for snippets as closure object
You can’t perform that action at this time.