2017 © Pedro Peláez
 

yii2-extension yii2-rtsphinxbehavior

Yii2 Behavior for working with Sphinx RealTime index

image

dezinger/yii2-rtsphinxbehavior

Yii2 Behavior for working with Sphinx RealTime index

  • Monday, March 19, 2018
  • by Dezinger
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 100 % Grown

The README.md

Yii2 Behavior for working with Sphinx RealTime index

Installation

The preferred way to install this extension is through composer., (*1)

Either run, (*2)

php composer.phar require dezinger/yii2-rtsphinxbehavior

or add, (*3)

"dezinger/yii2-rtsphinxbehavior": "dev-master"

to the require section of your composer.json file., (*4)

How to attach

namespace modules\blog\models;
use modules\blog\Module;
use modules\blog\components\RtSphinxBehavior;

class Post extends \yii\db\ActiveRecord {

    public function behaviors() {
        return [
                    'rtSphinxBehavior' => [
                        'class' => RtSphinxBehavior::className(),
                        'rtIndex' => Yii::$app->getModule('blog')->getParam('sphinxRtIndex'),
                        'idAttributeName' => 'id',
                        'rtFieldNames' => [
                            'name', 
                            'title', 
                            'description', 
                            'text'
                        ],
                        'rtAttributeNames' => [
                            'category_id', //RT attr and Post same name
                            'post_id' => 'id', //Attr mapping examle: rt.post_id = post.id
                            'parent_category_id' => 'category.parent_id', //Attr shortcut syntax example
                            'rating' => functon($model){return floatval($model->rating);}, //Usage closure example
                        ],
                        'enabled' => Yii::$app->getModule('blog')->getParam('isSphinxEnabled'),
                    ],
                ];   
    }

In this very example the rtIndex parameter gets value from blog-module paramener sphinxRtIndex. Then provide the names of attributes and fields from our main document fetch query, that is described in sphinx.conf in the source block., (*5)

How to configure RT index for Sphinx

source is_src
{
    type            = mysql

    sql_host        = localhost
    sql_user        = root
    sql_pass        =
    sql_db          = cms_db
    sql_port        = 3306  # optional, default is 3306

    sql_query_pre = SET NAMES utf8
    sql_query_pre = SET CHARACTER SET utf8

    sql_query = \
        SELECT id, category_id, UNIX_TIMESTAMP(date) AS date, name, title, description, text \
        FROM post

    sql_attr_uint       = category_id

    sql_field_string    = name
    sql_field_string    = title
    sql_field_string    = description   
    sql_field_string    = text  
}

The configuration block for RT index looks like this:, (*6)

index is_rt
{
    type            = rt
    docinfo         = extern

    rt_mem_limit    = 512M

    path            = /sphinx/data/is_rt
    stopwords       = /sphinx/stop/words.txt
    dict            = keywords
    morphology      = stem_ru, stem_en, soundex
    min_word_len    = 3
    min_prefix_len  = 3
    expand_keywords = 1
    index_exact_words = 1
    html_strip      = 1

    rt_field = name     
    rt_field = title
    rt_field = description
    rt_field = text

    rt_attr_uint = category_id
}

How it works

RtSphinxBehavior triggers on insert | update | delete events, processed by ActiveRecord class., (*7)

The Versions

19/03 2018

dev-master

9999999-dev

Yii2 Behavior for working with Sphinx RealTime index

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 yii yii 2 behavior yii framework sphinx rt index realtime index

19/03 2018

dev-develop

dev-develop

Yii2 Behavior for working with Sphinx RealTime index

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 yii yii 2 behavior yii framework sphinx rt index realtime index