mongosoft/yii2-xmlpipe

Sphinx XmlPipe 扩展程序,适用于 Yii 2

安装数: 8,243

依赖项: 0

建议者: 0

安全: 0

星星: 7

关注者: 4

分支: 0

类型:yii2-extension

0.1.1 2015-04-09 15:12 UTC

This package is auto-updated.

Last update: 2024-09-12 17:45:19 UTC


README

此扩展程序提供了一种简单的方法来为 Sphinx 搜索引擎创建 xmlpipe2 数据源。

Latest Stable Version Total Downloads

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

composer require --prefer-dist mongosoft/yii2-xmlpipe "*"

"mongosoft/yii2-xmlpipe": "*"

将以下内容添加到您的 composer.json 文件的 require 部分:

用法

XmlPipe 文档

<?php

namespace app\models;

use mongosoft\xmlpipe\BaseXmlPipe;

class XmlPipeDocument extends BaseXmlPipe
{
    /**
     * @inheritdoc
     */
    public function fields()
    {
        return [
            'name',
            'description',
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributes()
    {
        return [
            ['name' => 'type', 'type' => 'int', 'bits' => 16],
            ['name' => 'name', 'type' => 'string'],
            ['name' => 'description', 'type' => 'string'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function addDocuments()
    {
        $query = Items::find()
            ->select(['type', 'full_name', 'description'])
            ->asArray();

        foreach ($query->each() as $item) {
            $this->pushDocument([
                'type' => $item['type'],
                'name' => $item['full_name'],
                'description' => $item['description'],
            ]);
        }
    }
}

控制器

<?php

namespace app\controllers;

use yii\web\Controller;

class TestController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'xmlpipe' => [
                'class' => 'mongosoft\xmlpipe\Action',
                'document' => 'app\models\XmlPipeDocument',
            ],
        ];
    }
}

Sphinx 配置

将以下行添加到配置文件(sphinx.conf)中:

source myindex
{
    type               = xmlpipe2
    xmlpipe_command    = curl https:///test/xmlpipe
}

index myindex
{
    source             = myindex
    path               = /var/path/to/index/myindex
    docinfo            = extern
    morphology         = lemmatize_ru
    charset_type       = utf-8
}