日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

elastica php yii,Yii 1.1.*集成elasticsearch php 客户端Elastica

發(fā)布時間:2023/12/14 php 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 elastica php yii,Yii 1.1.*集成elasticsearch php 客户端Elastica 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Yii??是一個基于組件、用于開發(fā)大型 Web 應(yīng)用的高性能 PHP 框架。Yii提供了今日Web 2.0應(yīng)用開發(fā)所需要的幾乎一切功能。Yii是最有效率的PHP框架之一。官方網(wǎng)站

ElasticSearch ?是一個基于Lucene構(gòu)建的開源,分布式,RESTful搜索引擎。設(shè)計用于云計算中,能夠達(dá)到實時搜索,穩(wěn)定,可靠,快速,安裝使用方便。支持通過HTTP使用JSON進(jìn)行數(shù)據(jù)索引。

Elastica ?是用php寫的elasticsearch客戶端,通過Elastica可很方便的在php應(yīng)用中訪問elasticsearch,如:創(chuàng)建索引,添加文檔等。官方網(wǎng)站

在Yii中集成elasticsearch其實非常簡單:

第一步:將下載的Elastica整個拷貝到protected/vendors/目錄下(注意:如果是從github上clone下來的,應(yīng)該是Elastica下lib下面的Elastica)

第二步:編寫Elastica類自動導(dǎo)入文件,如?ElasticaAutoLoader.php

/**

* Description of ElasticaAutoLoader

*

* @author Owner

*/

class ElasticaAutoLoader {

/**

* @var array class prefixes

*/

static $prefixes = array(

'Elastica'

);

/**

* @var string path to where Zend classes root is located

*/

static $basePath = null;

/**

* Class autoload loader.

*

* @static

* @param string $className

* @return boolean

*/

static function loadClass($className) {

foreach (self::$prefixes as $prefix) {

if (strpos($className, $prefix . '_') !== false) {

if (!self::$basePath)

self::$basePath =

Yii::getPathOfAlias("application.vendors") . '/';

include self::$basePath . str_replace('_', '/', $className) . '.php';

return class_exists($className, false) ||

interface_exists($className, false);

}

}

return false;

}

}

?>

第三步:修改index.php文件

// change the following paths if necessary

$yii=dirname(__FILE__).'/../yii/framework/yii.php';

$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); require_once($yii);

Yii::createWebApplication($config)->run(); 改為:

// change the following paths if necessary

$yii = dirname(__FILE__) . '/../yii/framework/yii.php';

$config = dirname(__FILE__) . '/protected/config/main.php';

// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG', true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);

require_once(dirname(__FILE__) . '/protected/functions/yii.php');

require_once(dirname(__FILE__) . '/protected/functions/functions.php');

require_once($yii);

$app = Yii::createWebApplication($config);

// adding custom Zend Framework autoloader

Yii::import("application.vendors.*");

Yii::import("application.components.ElasticaAutoLoader", true);

Yii::registerAutoloader(array('ElasticaAutoLoader','loadClass'), true);

$app->run();

完成上面幾步就可以直接在程序中使用了!

總結(jié)

以上是生活随笔為你收集整理的elastica php yii,Yii 1.1.*集成elasticsearch php 客户端Elastica的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。