Yii  是一个基于组件、用于开发大型 Web 应用的高性能 PHP 框架。Yii提供了今日Web 2.0应用开发所需要的几乎一切功能。Yii是最有效率的PHP框架之一。官方网站

ElasticSearch  是一个基于Lucene构建的开源,分布式,RESTful搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。支持通过HTTP使用JSON进行数据索引。

Elastica  是用php写的elasticsearch客户端,通过Elastica可很方便的在php应用中访问elasticsearch,如:创建索引,添加文档等。官方网站

在Yii中集成elasticsearch其实非常简单:

第一步:将下载的Elastica整个拷贝到protected/vendors/目录下(注意:如果是从github上clone下来的,应该是Elastica下lib下面的Elastica)

第二步:编写Elastica类自动导入文件,如 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();

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

elastica php yii,Yii 1.1.*集成elasticsearch php 客户端Elastica相关推荐

  1. 第 4-8 课:Spring Boot 集成 ElasticSearch

    ElasticSearch 是⼀个开源的搜索引擎,建⽴在⼀个全⽂搜索引擎库 Apache Lucene™ 基础之上. Lucene 可以说是当下最先进.⾼性能.全功能的搜索引擎库--⽆论是开源还是私有 ...

  2. Java集成ElasticSearch及配置类工具类整理

    Java集成ElasticSearch及配置类工具类整理 前言:做一个有梦想的程序猿! ES不同的版本API差异比较大,此处ES版本为:6.5.3 代码如下: 添加Maven依赖 <!-- ES ...

  3. spring boot集成Elasticsearch客户端

    spring boot整合Elasticsearch客户端 在spring boot程序应用中集成Elasticsearch客户端,并通过配置对连接进行管理. Elasticsearch的客户端Jav ...

  4. Spring Boot 集成 Elasticsearch

    Elasticsearch (简称ES) 是一个基于 Lucene 的分布式.高扩展.高实时的搜索与数据分析引擎.本章介绍 Spring Boot 应用集成 Elasticsearch ,通过 Spr ...

  5. 【Spring Boot】21.集成elasticsearch

    2019独角兽企业重金招聘Python工程师标准>>> 简介 目前对于检索功能比较有名的服务是我们常见的elasticsearch,所以我们这一节的重点,也是针对elasticsea ...

  6. 史上最简单的Elasticsearch教程:SpringBoot集成Elasticsearch 实时流量监测平台

    SpringBoot集成Elasticsearch 实时流量监测平台 目录: 第一章:初尝 Elasticsearch 第二章:玩转 Kibana 第三章:开发原生 Elasticsearch 案例 ...

  7. GitChat优质文章-SpringBoot集成Elasticsearch

    Elasticsearch 是一个基于 Lucene 库的搜索引擎.Elasticsearch 是目前大数据领域最热门的技术栈之一.目前 Elasticsearch 被广泛应用在搜索.安全.数据分析等 ...

  8. springboot集成Elasticsearch实现各种搜索功能

    springboot集成Elasticsearch各类搜索功能实现 springboot集成Elasticsearch使用completion suggest实现自动关键字补全 建立学生的索引和映射: ...

  9. SpringData集成Elasticsearch

    Spring Data 是一个用于简化数据库.非关系型数据库.索引库访问,并支持云服务的 开源框架.其主要目标是使得对数据的访问变得方便快捷,并支持 map-reduce 框架和云计 算数据服务. S ...

最新文章

  1. WinServer2012中怎样设置静态IP
  2. 新手入门 | 上链第一步,如何完成XuperChain环境、服务部署
  3. PostgreSQL Oracle 兼容性之 - INDEX SKIP SCAN (递归查询变态优化) 非驱动列索引扫描优化...
  4. how2java_HOW-TO:在Spring 4和Java 7中使用@PropertySource批注
  5. Java面向对象(20)--接口
  6. JS之四舍五入Fixed
  7. 小小一行Python命令,居然把电脑变成服务器
  8. iPhone 12系列被曝量产延期:10月能见到就不错
  9. android datebinding学习
  10. 经典中的品味:第二章 C++基本的对象,类型和值(上)
  11. winform 项目获取app.config 中appSettings节点数据
  12. 系统分析与设计-敏捷迭代方法课后习题答案+学习笔记(答案见最后)
  13. 第三周 Access 课堂总结
  14. Liunx查看系统版本
  15. mybatis.org/dtd/mybatis-generator-config_1_0.dtd标红
  16. 用Python分析《斗破苍穹》
  17. 一套开源免费的OA办公管理系统源码,带小程序、生成APP
  18. 中国经济增长预期上调至8.5%;亚马逊药店提供常见处方药;中国外汇储备激增236亿美元…| 洞悉跨境
  19. 简单使用vue拖拽组件vue3-dnd
  20. 计算机教材黑皮书系列资源分享

热门文章

  1. ADS1.2 Error:(Fatal) L6002u:could not open file C:/...
  2. js获取摄像头权限实现拍照功能
  3. 中文版-Because He Lives-因他活着-好消息诗班(音乐河2)
  4. linux搭建泰拉瑞亚(Terraria)服务器
  5. 一行行的代码解密马尔可夫链
  6. Qt 设置父控件样式不影响子控件的解决方法
  7. 攻城略地mysql充值_攻城掠地充值有巨惠!平台折扣5.0超划算
  8. 阿里云服务器搭建wordpress个人博客
  9. 《我想进大厂》之Dubbo普普通通9问
  10. Centos7卸载自带的OpenJDK