Skip to content

wdmg/yii2-search

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Yii2 Downloads Packagist Version Progress GitHub license

Yii2 Search module

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.

This module is an integral part of the Butterfly.СMS content management system, but can also be used as an standalone extension.

Copyrights (c) 2019-2021 W.D.M.Group, Ukraine

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`
           '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 [ready to use]

  • v.1.1.4 - Fixed mysql syntax error: 1055 for MySQL >= 5.7
  • v.1.1.3 - Update dependencies
  • v.1.1.2 - Update dependencies, README.md
  • v.1.1.1 - Added multi-language support, events of support models
  • v.1.1.0 - Added LinguaStem() (support for Porter Stemmer)
  • v.1.0.10 - Update README.md and dependencies
  • v.1.0.9 - Checking module is loaded
  • 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

About

Search module for Yii2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages