`
zhengdl126
  • 浏览: 2509605 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

Sphinx mysql 安装和测试

阅读更多

参考网站
http://www.sphinxsearch.com/wiki/doku.php?id=sphinx_chinese_tutorial
http://ri0day.blogbus.com/logs/41975837.html

 

 

==========================================================1 安装
 因为我的LAMP环境已经配置好,所以只需要安装sphinx。


sphinx-0.9.8与MySQL5.1.x一起使用会出错,换成低版本的MySQL5.0.x


sudo apt-get install libmysqlclient15-dev


wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz

 

tar xzvf sphinx-0.9.8.1.tar.gz

 

cd sphinx-0.9.8.1/

 

./configure --prefix /usr/local/sphinx --with-mysql
make
sudo make install

 


==========================================================2 测试sphinx自带的demo。
  1、导入数据库文件example.sql。
      该文件在test数据库新建立一个documents,并插入基本的测试数据。
  2、修改sphinx.conf
cd /usr/local/sphinx/etc
cp sphinx.conf.dist sphinx.conf
vim sphinx.conf

 

主要修改以下几个参数
第一、连接数据库的用户名和密码


        sql_user        = root
  sql_pass        = ***** #你自己的密码


第二、索引路径

path      = /usr/local/sphinx/var/data/test1


==========================================================3 建立索引
indexer是建立索引的程序,具体参数可以在命令行下查看帮助


root@ubuntu-desktop:/usr/local/sphinx/etc# /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf test1
Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file '/usr/local/sphinx/etc/sphinx.conf'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.245 sec, 788.77 bytes/sec, 16.35 docs/sec

 

 

 

 

 

 

 

==========================================================4 开启查询的守护进程

/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf

 


E:\web\sphinx>bin\searchd --config sphinx.conf
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff

WARNING: forcing --console mode on Windows
using config file 'sphinx.conf'...
WARNING: index 'test1stemmed': preload: failed to open @CONFDIR@/data/test1stemm
ed.sph: No such file or directory; NOT SERVING
WARNING: index 'dist1': no such local index 'test1stemmed' - SKIPPING LOCAL INDE
X
creating server socket on 0.0.0.0:3312
accepting connections


注意开启3312端口,并修改相应的参数

 

==========================================================5 查询测试。
查询了两次,分别是ggart和another。结合数据库查看,结果是正确的。

root@ubuntu-desktop:/usr/local/sphinx/bin# /usr/local/sphinx/bin/search -c /usr/local/sphinx/etc/sphinx.conf ggart
Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file '/usr/local/sphinx/etc/sphinx.conf'...
index 'test1': query 'ggart ': returned 0 matches of 0 total in 0.000 sec

words:
1. 'ggart': 0 documents, 0 hits

index 'test1stemmed': search error: failed to open /usr/local/sphinx/var/data/test1stemmed.sph: No such file or directory.

 

 

 

root@ubuntu-desktop:/usr/local/sphinx/bin# /usr/local/sphinx/bin/search -c /usr/local/sphinx/etc/sphinx.conf another
Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file '/usr/local/sphinx/etc/sphinx.conf'...
index 'test1': query 'another ': returned 1 matches of 1 total in 0.000 sec

displaying matches:
1. document=3, weight=2, group_id=2, date_added=Sat Aug  8 23:34:22 2009
        id=3
        group_id=2
        group_id2=7
        date_added=2009-08-08 23:34:22
        title=another doc
        content=this is another group

words:
1. 'another': 1 documents, 2 hits

index 'test1stemmed': search error: failed to open /usr/local/sphinx/var/data/test1stemmed.sph: No such file or directory.

 

 

 

 

 

===================================调用Sphinx:未完待续

 

应用程序如果想调用Sphinx,可以从两个方面:

一是通过Sphinx官方提供的API接口(接口有Python,Java,Php三种版本)

二是通过安装SphinxSE(具体见1.2部分),然后创建一个中介sphinxSE类型的表,再通过执

行特定的SQL语句实现。

 

------------------通过官方API调用Sphinx(以PHP为例)

在sphinx解压目录有一个API目录,里面有三个PHP文件:test.php,test2.php和

sphinxapi.php。sphinxapi.php是sphinx调用接口封装文件,test.php是一个在命令行下执

行的查询例子文件,test2.php是一个生成摘要的例子文件。

在命令下行运行test.php(Linux上没有API目录,需要从源程序包中复制api目录

至/usr/local/sphinx)
cd /usr/local/sphinx
cp -rf /tmp/sphinx-0.9.8.1/api/ ./

Linux上(php在/usr/local/php目录???????????????????????????????????
,sphinx.conf在/usr/local/sphinx目录):
cd /usr/local/sphinx
/usr/local/php/bin/php api/test.php -i cgfinal CGArt

 

test2.php是一个摘要生成的例子文件,如果你的本地机器已装好sphinx,php运行环境,你

可以通过浏览器看查看test2.php的运行效果。


-------------------采用SphinxSE方式调用Sphinx
采用sphinxSE必须要求为mySQL安装sphinxSE Engine驱动
进入mysql命令行,运行show engines,看是不是有一个叫sphinx的engine,有的话就表示

sphinxSE(mysql的sphinx引擎)安装正常了


要创建一张sphinx 专用表,你可以这样建
CREATE TABLE `sphinx` (
`id` int(11) NOT NULL,
`weight` int(11) NOT NULL,
`query` varchar(255) NOT NULL,
`CATALOGID` INT NOT NULL,
`EDITUSERID` INT NOT NULL,
`HITS` INT NULL,
`ADDTIME` INT NOT NULL,
KEY `Query` (`Query`)
) ENGINE=SPHINX DEFAULT CHARSET=utf8

CONNECTION='sphinx://localhost:3312/cgfinal';
注:与一般mysql表不同的是ENGINE=SPHINX DEFAULT CHARSET=utf8

CONNECTION='sphinx://localhost:3312/cgfinal';,这里表示这个表采用SPHINXSE引擎,字

符集是utf8,与sphinx的连接串是'sphinx://localhost:3312/cgfinal,cgfinal是索引名称

 

 

 

 

分享到:
评论

相关推荐

    sphinx 参考手册和源程序

    6.2.3. SphinxSE 安装测试 6.3. 使用 SphinxSE 7. 报告 bugs 8. sphinx.conf 选项参考 8.1. Data source 配置选项 8.1.1. type 8.1.2. sql_host 8.1.3. sql_port 8.1.4. sql_user 8.1.5. sql_pass 8.1.6. sql_...

    Sphinx中文参考手册.rar

    6.2.3. SphinxSE 安装测试 6.3. 使用 SphinxSE 7. 报告 bugs 8. sphinx.conf 选项参考 8.1. Data source 配置选项 8.1.1. type 8.1.2. sql_host 8.1.3. sql_port 8.1.4. sql_user 8.1.5. sql_pass 8.1.6. ...

    高性能MySQL(第3版).part2

    2.5.5Percona的TPCC—MySQL测试工具63 2.6总结65 第3章服务器性能剖析67 3.1性能优化简介67 3.1.1通过性能剖析进行优化69 3.1.2理解性能剖析71 3.2对应用程序进行性能剖析72 3.2.1测量PHP应用程序74 3.3剖析...

    高性能MySQL(第3版).Baron.Scbwartz_2

    第1章 mysql 架构与历史 1 第2章 mysql 基准测试 35 第3章 服务器性能剖析 67 第4章 schema 与数据类型优化 111 第5章 创建高性能的索引 141 第6章 查询性能优化 195 第7章 mysql 高级特性 259 第8章 优化服务器设置...

    高性能MySQL(第3版)

    第2章 MySQL 基准测试 第3章 服务器性能剖析 第4章 Schema 与数据类型优化 第5章 创建高性能的索引 第6章 查询性能优化 第7章 MySQL 高级特性 第8章 优化服务器设置 第9章 操作系统和硬件优化 第10章 复制 ...

    高性能MySQL(第3版).Baron.Scbwartz_1

    第2章 mysql 基准测试 35 第3章 服务器性能剖析 67 第4章 schema 与数据类型优化 111 第5章 创建高性能的索引 141 第6章 查询性能优化 195 第7章 mysql 高级特性 259 第8章 优化服务器设置 325 第9章 操作系统和硬件...

    基于Sphinx 0.9.8 开发的中文全文搜索引擎Coreseek

    基于Sphinx 0.9.8 开发 支持Mysql全文搜索,支持PHP开发。 新增如下特性: 修正 2.5.x 系列searchd可能崩溃的Bug 改进 高亮的算法,支持词权重自定义 改进 切分算法,支持必须出现的关键词(仅在简单查询模式...

    sphinx:被遗弃,请参阅https

    安装go get github.com/yunge/sphinx 测验在mysql中将“ documents.sql”导入“测试”数据库; 在sphinx.conf中更改mysql密码; 将test.xml复制到sphinx.conf中的默认目录: cp test.xml /usr/local/sphinx/var/data...

    PHP特级课:LVS负载均衡:搜索引擎.docx

    第26集 Sphinx安装与测试 43分钟 第27集 Coreseek安装与测试 45分钟 第28集 PHP搜索代码测试 53分钟 第29集 Sphinx实时索引 56分钟 第 9 章: Mongodb数据库(上) 第30集 Mongodb安装和使用 55分钟 第31集 Mongodb...

    php+mysql专家编程源码

    《PHP+MySQL专家编程》内容简介:构建当前需求最严苛应用程序的最佳实践和专家技能,作为世界上最流行、最通用的开放源代码脚本语言,PHP经常会与My SQL一起被用于构建大业务量、处理关键任务的应用程序。...

    codesearch:Sphinx(搜索)索引器和搜索页面

    数据库后端后端由 Sphinx(用 2.1.9 测试)和 MySQL 组成。 提供了一个 SQL 文件scripts/create_db.sql来初始化 MySQL。 如果你通读它,你会看到它连接到 mysql @localhost,所以在部署 MySQL 的主机上运行它。索引...

    LAMP兄弟连-特级课课程

    LAMP兄弟连-特级课课程大纲 ...第七天 Cacti网络监控、邮件报警和LAMP压力测试 第八天 Sphinx全文索引 第九天 Mongodb数据库上 第十天 Mongodb数据库下 第十一天 Sphinx完整项目设计 第十二天 Songodb完整项目设计

    JaverSphinxBundle:Symfony捆绑包,使用SphinxQL将Sphinx搜索引擎与Symfony集成在一起

    SphinxQL查询生成器与整合与集成Symfony Profiler工具栏部分,其中包含已执行查询的数量,以及Profiler页面,其中包含有关已执行查询的详细信息使用场景测试搜索的能力要求PHP 7.1以上pdo_mysql php扩展安装使用...

    多人Web开发环境的解决方案

    目前常用的一些做法是在个人PC上搭建一套Web运行环境,如:PHP,Apache,MySQL,Memcached等,所有的开发、调试、测试工作都在个人电脑PC上完成。但是由于Web开发涉及到新技术越来越多,像Redis,Sphinx等技术已经...

    浅谈MySQL存储引擎选择 InnoDB与MyISAM的优缺点分析

    下面先让我们回答一些问题: ◆你的数据库有外键吗? ◆你需要事务支持吗?... 数据的大小,是一个影响你选择什么样存储引擎的重要因素,大尺寸的数据集趋向于选择InnoDB方式,因为其支持事务处理和故障恢复

    yii-based-torrent-tracker

    ##这是一个测试版,仅用于开发目的,但许多功能完全可用###以下是一些功能: 用户帐户(登录、社交网络登录、设置等) 种子:根据类别设置创建种子组。 上传 torrent 到组,编辑它们等。用于描述的 EAV 结构。 ...

    搜猫搜索引擎 X2

    该内核集合了元搜和sphinx于一身的高级搜索内核!使搜索结果永久少于0.1秒!能非常流畅的运行!不管你用的服务器配置多低也不用怕了!告别高配置的干扰了! 该版本完全免费,提供给搜索引擎爱好者研究测试等. EXE...

    BT搜索引擎ssbc.zip

    作为最早在国内研究和实践DHT爬虫的人,我的灵感是来自...Sphinx创建全文索引的速度很给力,官方的自评也很高,我自己测试1000w的资源(大概3GB),1分钟左右就索引完毕。不信,大家可以自测一下。 标签:ssbc

Global site tag (gtag.js) - Google Analytics