好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>后端语言>PHP
<tfoot draggable='sEl'></tfoot>

sphinxphp使用 sphinx安装

很多站长朋友们都不太清楚sphinxphp使用,今天小编就来给大家整理sphinxphp使用,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 php windows下怎么安装sphinx,安装后又怎么使用 2、 php怎么连接访问sphinx,coreseek 3、 think php3.2怎么实现sphinx搜索 4、 电脑-Sphinx在windows下安装使用[支持中文全文检索] php windows下怎么安装sphinx,安装后又怎么使用

1、下载,我这里下的是“Win64 binaries w/MySQL+PgSQL+libstemmer+id64 support”,下载后文件名:sphinx-2.0.6-release-win64-id64-full.zip;

2、将其解压到D: \ sphinx,并在D:\sphinx下新建目录data(用来存放索引文件)与log(用来存放日志文件);

3、将D:\sphinx\sphinx.conf.in复制到D:\sphinx\bin\sphinx.conf.in,并重命名为sphinx.conf;

4、修改 D:\sphinx\bin\sphinx.conf 如下:

4.1、搜索source src1修改{...}中的内容

# 使用的数据库类型

type = mysql

# 服务器

sql_host = localhost

# 数据库登录名

sql_user = root

# 数据库登录密码

sql_pass = root

# 操作的数据库名称

sql_db = test

# 数据库服务器端口

sql_port = 3306

# 设置编码,如果用的是utf-8编码

sql_query_pre = SET NAMES utf-8

(以上7条前如有#将其删除)

4.2、搜索index test1修改{...}中的内容

# 放索引的目录

path = D:/sphinx/data/

# 编码

charset_type = utf-8

# 指定utf-8编码表

charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F

# 简单分词,只有0和1,需要搜索中文必须置1

ngram_len = 1

# 需要分词的字符,搜索中文时必须

ngram_chars = U+3000..U+2FA1F

(以上5条前如有#将其删除)

5、导入测试数据将D:\sphinx\example.sql中语句执行到test数据库中,注意:test数据库创建时需要指定为utf-8格式;

6、打开cmd窗口,进入目录D:\sphinx\bin;

7、建立索引,执行indexer.exe test1,test1即为sphinx.conf中index test1

Sphinx 2.0.6-id64-release (r3473)

Copyright (c) 2001-2012, Andrew Aksyonoff

Copyright (c) 2008-2012, Sphinx Technologies Inc (

using config file './sphinx.conf'...

indexing index 'test1'...

collected 4 docs, 0.0 MB

sorted 0.0 Mhits, 100.0% done

total 4 docs, 222 bytes

total 0.019 sec, 11252 bytes/sec, 202.74 docs/sec

total 2 reads, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg

total 9 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg

成功...

8、搜索'test',执行search.exe test

Sphinx 2.0.6-id64-release (r3473)

Copyright (c) 2001-2012, Andrew Aksyonoff

Copyright (c) 2008-2012, Sphinx Technologies Inc ()

using config file './sphinx.conf'...

index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:

1. document=1, weight=2421, group_id=1, date_added=Tue Feb 26 10:25:31 2013

id=1

group_id=1

group_id2=5

date_added=2013-02-26 10:25:31

title=test one

content=this is my test document number one. also checking search within

phrases.

2. document=2, weight=1442, group_id=3, date_added=Tue Feb 26 10:25:31 2013

id=2

group_id=3

group_id2=6

date_added=2013-02-26 10:25:31

title= ????

content=this is my test document number two ???????

3. document=4, weight=1442, group_id=2, date_added=Tue Feb 26 10:25:31 2013

id=4

group_id=2

group_id2=8

date_added=2013-02-26 10:25:31

title=doc number four

content=this is to test groups

words:

1. 'test': 3 documents, 4 hits

index 'test1stemmed': search error: failed to open D:/sphinx/data/test1stemmed.s

ph: No such file or directory.

最后面的一句error可忽略;

9、搜索中文,首先将数据库中的内容update含有中文,执行sql语句:

UPDATE documents SET title='中文', content='this is my test document number one. also checking search within phrases.含有中文。' WHERE id=1;

UPDATE documents SET title='中文标题', content='this is my test document number one. also checking search within phrases.含有中文内容。' WHERE id=2;

UPDATE documents SET title='中文标题测试', content='this is my test document number one. also checking search within phrases.含有中文内容。' WHERE id=3;

重新建立索引(执行第7步);

然后执行search.exe 中文

Sphinx 2.0.6-id64-release (r3473)

Copyright (c) 2001-2012, Andrew Aksyonoff

Copyright (c) 2008-2012, Sphinx Technologies Inc ()

using config file './sphinx.conf'...

indexing index 'test1'...

collected 4 docs, 0.0 MB

sorted 0.0 Mhits, 100.0% done

total 4 docs, 349 bytes

total 0.025 sec, 13808 bytes/sec, 158.26 docs/sec

total 2 reads, 0.000 sec, 0.3 kb/call avg, 0.0 msec/call avg

total 9 writes, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg

D:\sphinx\bin>search.exe 中文

Sphinx 2.0.6-id64-release (r3473)

Copyright (c) 2001-2012, Andrew Aksyonoff

Copyright (c) 2008-2012, Sphinx Technologies Inc ()

using config file './sphinx.conf'...

index 'test1': query '中文 ': returned 0 matches of 0 total in 0.000 sec

words:

index 'test1stemmed': search error: failed to open D:/sphinx/data/test1stemmed.s

ph: No such file or directory.

没有搜索到,因为windows命令行中的中文时GBK编码格式,所以没有匹配内容。我们可以使用PHP程序来试试;

10、进入D:\sphinx\api\目录,可以发现sphinx支持php、java、ruby调用,并提供对应的test例子,这里我们使用php来操作,首先将api复制到D:\www\下并重命名为sphinxapi,因为我本机上apache的web目录为D:\www,在D:\www\sphinxapi\下新建search.php,内容为:

<?php

require 'sphinxapi.php';

$s = new SphinxClient();

$s->SetServer('localhost', 9312);

$result = $s->Query('中国');

print_r($result);

echo '<br /><br />';

$result = $s->Query('中文');

print_r($result);

?>

然后回到cmd命令行中,开启sphinx服务,执行searchd.exe(这个必须要执行的)

Sphinx 2.0.6-id64-release (r3473)

Copyright (c) 2001-2012, Andrew Aksyonoff

Copyright (c) 2008-2012, Sphinx Technologies Inc ()

using config file './sphinx.conf'...

WARNING: compat_sphinxql_magics=1 is deprecated; please update your application

and config

WARNING: preopen_indexes=1 has no effect with seamless_rotate=0

listening on all interfaces, port=9312

listening on all interfaces, port=9306

precaching index 'test1'

precaching index 'test1stemmed'

WARNING: index 'test1stemmed': preload: failed to open D:/sphinx/data/test1stemm

ed.sph: No such file or directory; NOT SERVING

precaching index 'rt'

WARNING: index 'rt': preload: failed to open @CONFDIR@/data/rt.lock: No such fil

e or directory; NOT SERVING

precached 3 indexes in 0.018 sec

成功...

然后在浏览器中执行,打印出来的数组结果可以很清晰的看见搜索的结果比对。。。

11、至此sphinx在windows下的简单安装与使用就完成了。

php怎么连接访问sphinx,coreseek

修改配置文件,

建立分词索引,

启动sphinx的服务,

将sphinx类文件放在项目中,

引入,实例化类,

设置sphinx服务地址和端口号,

然后就可以调用query方法检索,

以上,作为一款免费的中文分词软件很不错....

think php3.2怎么实现sphinx搜索

今天开始通过php程序使用sphinx搜索,以后做为记录

1.启动sphinx服务

/usr/local/coreseek/bin/searchd 其中几个参数可以通过 -h查看

-c, -config <file> 指定coreseek中的配置文件(默认为csft.conf),位置为/usr/lcoal/coreseek/etc/中

–stop 用来停掉 searchd,使用csft.conf中所指定的PID文件,因此您可能还需要用

–config选项来确认searchd使用哪个配置文件。

值得 注意的是,调用 –stop 会确保用 UpdateAttributes() 对索引进行的更动会反应到实际的索引文件中去。示例: $ searchd –config /usr/lcoal/coreseek/etc/csft.conf –stop

–status 用来查询运行中的searchd实例的状态,使用指定的(也可以不指定,使用默认)配置文件中描述的连接参数。它通过配置好的第一个UNIX套接字或 TCP端口与运行中的实例连接。一旦连接成功,它就查询一系列状态和性能计数器的值并把这些数据打印出来。在应用程序中,可以用Status() API调用来访问相同的这些计数器

具体可以参考:参数说明

2.php加载sphinx模块,要想在php中使用sphinx一般有两种方式

2.1 加载sphinx模块

2.2 引入sphinxapi类(/home/book/Downloads/sphinx/coreseek-3.2.14/csft-3.2.14/api/目录中) 考虑到每个使用sphinx的php文件都得引入sphinxapi类,为了方便与学习,尝试用加载模块的办法。

步骤一 wget

步骤二 tar zxf sphinx-1.1.0.tgz cd sphinx-1.1.0 /usr/local/php/bin/phpize (生成config文件) ./configure –with-php-config=/usr/local/php/bin/php-config 提示出错 checking for libsphinxclient headers in default path …… 找到libsphinxclient 在之前的 /home/book/Downloads/sphinx/coreseek-3.2.14/csft-3.2.14/api/目录下 进入相关目录安装 ./configure make make install 安装完 libsphinxclient 然后继续安装sphinx扩展

电脑-Sphinx在windows下安装使用[支持中文全文检索]

前一阵子尝试使用了一下Sphinx,一个能够被各种语言(PHP/Python/Ruby/etc)方便调用的全文检索系统。网上的资料大多是在linux环境下的安装使用,当然,作为生产环境很有必要部署在*nix环境下,作为学习测试,还是windows环境比较方便些。

本文旨在提供一种便捷的方式让Sphinx在windows下安装配置以支持中文全文检索,配置部分在linux下通用。

一、关于Sphinx

Sphinx 是一个在GPLv2 下发布的一个全文检索引擎,商业授权(例如, 嵌入到其他程序中)需要联系作者(Sphinxsearch测试数据)以获得商业授权。

一般而言,Sphinx是一个独立的搜索引擎,意图为其他应用提供高速、低空间占用、高结果相关度的全文搜索功能。Sphinx可以非常容易的与SQL数据库和脚本语言集成。

当前系统内置MySQL和PostgreSQL 数据库数据源的支持,也支持从标准输入读取特定格式的XML数据。通过修改源代码,用户可以自行增加新的数据源(例如:其他类型的DBMS的原生支持)。

搜索API支持PHP、Python、Perl、Rudy和Java,并且也可以用作MySQL存储引擎。搜索API非常简单,可以在若干个小时之内移植到新的语言上。

Sphinx特性:

高速的建立索引(在当代CPU上,峰值性能可达到10MB/秒); 高性能的搜索(在2–4GB的文本数据上,平均每次检索响应时间小于0.1秒); 可处理海量数据(目前已知可以处理超过100GB的文本数据,在单一CPU的系统上可处理100M文档); 提供了优秀的相关度算法,基于短语相似度和统计(BM25)的复合Ranking方法; 支持分布式搜索; 提供文件的摘录生成; 可作为MySQL的存储引擎提供搜索服务; 支持布尔、短语、词语相似度等多种检索模式; 文档支持多个全文检索字段(最大不超过32个); 文档支持多个额外的`属性信息(例如:分组信息,时间戳等); 停止词查询; 支持单一字节编码和UTF-8编码; 原生的MySQL支持(同时支持MyISAM和InnoDB); 原生的PostgreSQL支持.

中文手册可以在这里获得(酷勤网备用下载地址:sphinx_doc_zhcn_0.9.pdf)。

二、Sphinx在windows上的安装

1.直接在找到最新的windows版本,我这里下的是Win32 release binaries with MySQL support,下载后解压在D:sphinx目录下;

2.在D:sphinx下新建一个data目录用来存放索引文件,一个log目录方日志文件,复制D:sphinxsphinx.conf.in到D:sphinxbinsphinx.conf(注意修改文件名);

3.修改D:sphinxbinsphinx.conf,我这里列出需要修改的几个:

type= mysql # 数据源,我这里是mysqlsql_host;= localhost # 数据库服务器sql_user;= root # 数据库用户名sql_pass;=;'' # 数据库密码sql_db;;;= test # 数据库sql_port;= 3306 # 数据库端口

sql_query_pre;;;= SET NAMES utf8 # 去掉此行前面的注释,如果你的数据库是uft8编码的

index test1{#;放索引的目录;path;;;= D:/sphinx/data/# 编码;charset_type;;= utf-8;#; 指定utf-8的编码表;charset_table=0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F;# 简单分词,只支持0和1,如果要搜索中文,请指定为1;ngram_len;;;;= 1# 需要分词的字符,如果要搜索中文,去掉前面的注释;ngram_chars;;;= U+3000..U+2FA1F}

# index test1stemmed : test1# {;# path;;;= @CONFDIR@/data/test1stemmed;# morphology;;= stem_en# }# 如果没有分布式索引,注释掉下面的内容# index dist1# {;# 'distributed' index type MUST be specified;# type;;;;= distributed

;# local index to be searched;# there can be many local indexes configured;# local;;;;= test1;# local;;;;= test1stemmed

;# remote agent;# multiple remote agents may be specified;# syntax is 'hostname:port:index1,[index2[,...]];# agent;;;;= localhost:3313:remote1;# agent;;;;= localhost:3314:remote2,remote3

;# remote agent connection timeout, milliseconds;# optional, default is 1000 ms, ie. 1 sec;# agent_connect_timeout;= 1000

;# remote agent query timeout, milliseconds;# optional, default is 3000 ms, ie. 3 sec;# agent_query_timeout;;= 3000# }

# 搜索服务需要修改的部分searchd{;# 日志;log;;;;;= D:/sphinx/log/searchd.log

;# PID file, searchd process ID file name;pid_file;;;= D:/sphinx/log/searchd.pid

# windows下启动searchd服务一定要注释掉这个 # seamless_rotate;;= 1}

4.导入测试数据

C:Program FilesMySQLMySQL Server 5.0bin>mysql -uroot test<d:/sphinx/example.sql

5.建立索引

D:sphinxbin>indexer.exe test1

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

using config file ‘./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.101 sec, 1916.30 bytes/sec, 39.72 docs/sec

D:sphinxbin>

6.搜索’test’试试

D:sphinxbin>search.exe test

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

using config file ‘./sphinx.conf’…

index ‘test1′: query ‘test ‘: returned 3 matches of 3 total in 0.000 sec

displaying matches:

1. document=1, weight=2, group_id=1, date_added=Wed Nov 26 14:58:59 2008

;;;;;id=1

;;;;;group_id=1

;;;;;group_id2=5

;;;;;date_added=2008-11-26 14:58:59

;;;;;title=test one

;;;;;content=this is my test document number one. also checking search within

;phrases.

2. document=2, weight=2, group_id=1, date_added=Wed Nov 26 14:58:59 2008

;;;;;id=2

;;;;;group_id=1

;;;;;group_id2=6

;;;;;date_added=2008-11-26 14:58:59

;;;;;title=test two

;;;;;content=this is my test document number two

3. document=4, weight=1, group_id=2, date_added=Wed Nov 26 14:58:59 2008

;;;;;id=4

;;;;;group_id=2

;;;;;group_id2=8

;;;;;date_added=2008-11-26 14:58:59

;;;;;title=doc number four

;;;;;content=this is to test groups

words:

1. ‘test’: 3 documents, 5 hits

D:sphinxbin>

都所出来了吧。

6.测试中文搜索

修改test数据库中documents数据表,

UPDATE `test`.`documents` SET `title` = ‘测试中文’, `content` = ‘this is my test document number two,应该搜的到吧’ WHERE `documents`.`id` = 2;

重建索引:

D:sphinxbin>indexer.exe –all

搜索’中文’试试:

D:sphinxbin>search.exe 中文

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

using config file ‘./sphinx.conf’…

index ‘test1′: query ‘中文 ‘: returned 0 matches of 0 total in 0.000 sec

words:

D:sphinxbin>

貌似没有搜到,这是因为windows命令行中的编码是gbk,当然搜不出来。我们可以用程序试试,在D:sphinxapi下新建一个foo.php的文件,注意utf-8编码

<?php

require ’sphinxapi.php’;

$s = new SphinxClient();

$s->SetServer(’localhost’,3312);

$result = $s->Query(’中文’);

var_dump($result);

?>

启动Sphinx searchd服务

D:sphinxbin>searchd.exe

Sphinx 0.9.8-release (r1533)

Copyright (c) 2001-2008, Andrew Aksyonoff

WARNING: forcing –console mode on Windows

using config file ‘./sphinx.conf’…

creating server socket on 0.0.0.0:3312

accepting connections

执行PHP查询:

php d:/sphinx/api/foo.php

结果是不是出来?剩下的工作就是去看手册,慢慢摸索高阶的配置。

关于sphinxphp使用的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于sphinxphp使用 sphinx安装的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did197686
更新时间:2023-04-26   阅读:20次

上一篇: phpsocket接口 php socket_write

下一篇:php104mvc框架 php c框架

相关资讯

最新资料更新

  • 1.php技术网学习 php技术门户
  • 2.phpmysql框架 php框架yii
  • 3.朔州php后台开发 朔州php培训招聘
  • 4.php数组逗号分隔 php中的输出语句 能使用逗号分隔多个表达式
  • 5.php登录保护机制 php保持登录状态
  • 6.数组对象转为数组php 对象数组转string
  • 7.php保存用户信息 php登录成功保存session
  • 8.proxy.php proxyphp?url
  • 9.php表格循环 php循环函数
  • 10.PHP添加日期代码 php年月日时间代码
  • 11.php俄罗斯方块 俄罗斯方块的网址
  • 12.PHP中嵌入script php嵌入html有哪几种方法
  • 13.20个php函数 php的system函数
  • 14.php怎么开发xml php处理xml数据
  • 15.修改php网页链接 怎么修改php网页
  • 16.php环境配置工具 phpstorm2021配置php环境
  • 17.免费php空间shery 免费PHP空间 免备案 V52版本
  • 18.php接口和抽象类的区别 php抽象函数
  • 19.php在线直播详解 php直播用的什么技术
  • 20.php代码修改按钮大小 php内容修改

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网」
[ SiteMap ]