导航:首页 > 程序命令 > sphinx命令

sphinx命令

发布时间:2022-04-23 02:12:07

A. 如何使用sphinx生成python第三方模块的文档

在使用Python的过程中,无疑我们经常需要下载安装第三方模块(如何安装:URL),而安装后我们必然会面临一个使用的问题,这时候我们需要阅读相关的文档。可是我们会发现下载的第三方模块目录的doc文件夹下只有一个conf.py文件和一些后缀为rst的文件,文档在哪里呢?
其实Python提供了专用的文档生成工具,有了这些工具就可以很方便地生成我们需要的文档了。本文就是介绍如何使用一些第三方工具(sphinx)来生成这些文档。
1.下载并安装Docutils:http://docutils.sf.net/。
2.下载并安装sphinx :http://pypi.python.org/pypi/Sphinx/1.1。Sphinx 是用来生成文档的,设计的初衷是为了生成python的文档。可以生成html、htmlhelp/chm、qthelp、devhelp、latex、man 等格式的文档。
3.在Widnows环境下,打开命令提示符,使用cd /d 命令将当前目录切换至Sphinx目录,运行命令:python sphinx-build.py -b html sourcedir builddir,其中,-b后面的字符串用于控制输出文档的格式,默认为html。sourcedir表示文档来源文件夹(一般就是包含conf.py文件的那个文件夹),builddir表示生成文档的目标文件夹。(注:在Windows环境下,请不要将sphinx文件夹、sourcedir 和builddir 设置成包含中文的路径,否则容易出现一些默名其妙的错误,例如编码错误。)

B. 如何调用Sphinx 和api接口

如何调用Sphinx

按上面配置,第5节点对数据库进行了索引,通过Sphinx自带的search(在bin/release目录)就可以在命令行进行搜索:

(搜索CGArt)
windows上:
search -c d:/sphinx/sphinx.conf CGArt
Linux上:
cd /usr/local/sphinx
./bin/search -c sphinx.conf CGArt
运行后,系统提示一堆信息:
....
....
words:
1. 'cgart': 36 documents, 189 hits
这个表示库中有36条记录符合要求,出现CGArt的有189处。应用程序如果想调用Sphinx,可以从两个方面:

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

二是通过安装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)

Windows上:
D:\sphinx\bin\release>c:\php5.2\php.exe -c c:\php5.2\php.ini ..\..\api\test.php -i cgfinal CGartLinux上(php在/usr/local/php目录,sphinx.conf在/usr/local/sphinx目录):

cd /usr/local/sphinx
/usr/local/php/bin/php api/test.php -i cgfinal CGArtSphinx的API查询接口主要有这些内容(其实对照 一下sphinxapi.php就清楚了):

//创建Sphinx的客户端接口对象
$cl = new SphinxClient ();

//设置连接Sphinx主机名与端口
$cl->SetServer('localhost',3312);

//可选,为每一个全文检索字段设置权重,主要根据你在sql_query中定义的字段的顺序,Sphinx系统以后会调整,可以按字段名称来设定权重
$cl->SetWeights ( array ( 100, 1 ) );

//设定搜索模式,SPH_MATCH_ALL,SPH_MATCH_ANY,SPH_MATCH_BOOLEAN,SPH_MATCH_EXTENDED,SPH_MATCH_PHRASE
$cl->SetMatchMode(SPH_MATCH_ALL);

//设定过滤条件$attribute是属性名,相当于字段名(用SPH_MATCH_EXTENDED时),$value是值,$exclude是布尔型,
当为true时,相当于$attribute!=$value,默认值是false
$cl->SetFilter($attribute, $values, $exclude);

//设定group by
//根据分组方法,匹配的记录集被分流到不同的组,每个组都记录着组的匹配记录数以及根据当前排序方法本组中的最佳匹配记录。
//最后的结果集包含各组的一个最佳匹配记录,和匹配数量以及分组函数值
//结果集分组可以采用任意一个排序语句,包括文档的属性以及sphinx的下面几个内部属性
//@id--匹配文档ID
//@weight, @rank, @relevance--匹配权重
//@group--group by 函数值
//@count--组内记录数量
//$groupsort的默认排序方法是@group desc,就是按分组函数值大小倒序排列
$cl->SetGroupBy($attribute, $func, $groupsort);

//设定order by的内容,第一个参数是排序方法名,值有
// SPH_SORT_RELEVANCE,SPH_SORT_ATTR_DESC,SPH_SORT_ATTR_ASC,SPH_SORT_TIME_SEGMENTS,SPH_SORT_EXTENDED
//$sortby的值如"HITS desc"
$cl->SetSortMode(SPH_SORT_EXTENDED, $sortby);

//set count-distinct attribute for group-by queries,$distinct为字符串
$cl->SetGroupDistinct ( $distinct );

//相当于mysql的limit $offset,$limit
$cl->SetLimits($start,$limit)

//$q是查询的关键字,$index是索引名称,当等于*时表查询所有索引

C. php中如何使用sphinx搜索引擎

一. 安装、配置

1.ubuntu安装sphinx

如果没有安装aptitude ,需要先安装 aptitude

2.配置

3.执行命令分词,会在/var/lib/sphinxsearch/data/test1 目录下生成一堆索引文件

sudo indexer -c /etc/sphinxsearch/sphinx.conf test1

test1为上述配置文件的index名字

4.命令行测试搜索

sudo search -c /etc/sphinxsearch/sphinx.conf google

二.在php中使用,安装php、sphinx的依赖库

  1. 安装 aptitudeapt-get install aptitude

sudo aptitude install libsphinxclient-dev libsphinxclient-0.0.1 -y

2.安装php sphinx的扩展

安装 pecl
sudo apt-get install php-pear php5-dev
在安装sphinx
sudo pecl install sphinx

3.在配置文件php.ini中添加sphinx的扩展,

我的php.ini文件为
sudo vim /etc/php5/fpm/php.ini
获取自己的php.ini文件位置使用
php5-fpm -i|grep ini

添加:
extension=sphinx.so


4.重启php5-fpm,查看php是否加载sphinx模块
sudo /etc/init.d/php5-fpm restart


5.将search程序运行在后台
sudo searchd -c /etc/sphinxsearch/sphinx.conf
默认监听配置文件中的端口:9312

6.在thinkphp中调用搜索

搜索完毕,返回结果(默认返回20条,修改返回条数用添加$s->SetLimits(0, 1000, 1000);),搜索速度相当快,索引80w条数据的title和description两个字段耗时不到10s,该搜索引擎支持增量索引,多种模式的搜索,网上的资料也非常多

D. 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 (http://sphin

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 (http://sphinxsearch.com)

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 (http://sphinxsearch.com)

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 (http://sphinxsearch.com)

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 (http://sphinxsearch.com)

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
成功...
然后在浏览器中执行http://localhost/sphinxapi/search.php,打印出来的数组结果可以很清晰的看见搜索的结果比对。。。
11、至此sphinx在windows下的简单安装与使用就完成了。

E. sphinx 和coreseek 有什么区别

然后重新运行aclocal和autoconf
aclocal && autoconf
最后再次运行automake
automake


然后继续mmseg的安装
./configure --prefix=/usr/local/mmseg
make && make install


如果make 报错
There is an easy fix when you get such messages as "X--tag=CXX: command not found".
Just type:
export echo=echo
And try again.


所以输入
export echo=echo
然后再次运行安装
make && make install


安装csft
./configure --prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql --with-mmseg=/usr/local/mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/
make && make install
安装完毕后 注意 coreseek 中的配置文件也是csft.conf 而不是 sphinx.conf
cd /usr/local/coreseek/etc
cp sphinx.conf.dist csft.conf
vim csft.conf


有些配置改动如下其他配置内容如上文的sphinx.conf
在索引源中注释掉txt
index main{
#stopwords = G:datastopwords.txt
#wordforms =G:datawordforms.txt
#exceptions =/data/exceptions.txt
#charset_type = sbcs
#添加下面2行 意思是把中文分词加入到配置文件中
char_type = zh_cn.utf-8
charset_dictpath =/usr/local/mmseg/etc/ #你安装mmseg的目录
}


保存配置
建立索引
cd /usr/local/coreseek/bin
./indexer --all
./search 中文词缀


如何用php去使用sphinx
Sphinx集成到php程序中有两种方式


  1. Sphinx php 模块(这次我们选择使用的方式)

  2. 2.Sphinx api 类(位于coreseek源码包里的csft里的api文件夹里有一个sphinxapi.php,使用的时候包含这个php文件即可)


我们要使用sphinx需要做以下几件事:


  1. 首先要有数据

  2. 2.建立sphinx配置文件

  3. 3.生成索引

  4. 4,启动searchd 服务进程,并开启端口9312

  5. 5.用php客户程序去链接sphinx服务


/usr/local/coreseek/bin/searchd

启动进程命令 searchd
-c 指定配置文件
--stop 停止服务
--pidfile 显示指定pid文件
-p 指定端口(默认9312)
注意:这里启动的服务是searchd


使用php sphinx的模块
下载 sphinx-1.1.0.tgz


tar zvxf sphinx-1.1.0.tgz
cd sphinx-1.1.0
/usr/local/php/bin/phpize #用于生成一个configure的脚本
进入coreseek源码包的csft/api/libsphinxclent 目录下执行configure
./configure
make && make install
进入sphinx-1.1.0.gzt的源码包目录下 执行configure用于生成so 的shpinx模块
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-sphinx
make && make install
安装成功后会有提示
Build complete.
Don't forget to run 'make test'.


Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ (这个目录是sphinx.so所在的目录)


然后我们编辑php的ini文件 在extension中加入
extension=sphinx.so


然后重启nginx和php的服务
最后打印一下phpinfo 查看sphinx是否开启成功
如果成功开启 就可以使用php手册里的sphinx的方法和代码了

F. sphinx sqlattruint 字段别名不起作用吗

不是的,sphinx sqlattruint 字段别名不起作用的原因如下:

1、表里没有相应的数据。

具体解决办法:设置相应的表格数据,重新新建表格。

2、sql的查询语句出现错误。

具体解决办法:更换相应的语句错误处。

如下:

sql_query=SELECTproct_attribute_idFROMproct_attribute

SQLcode12SELECTproct_attribute_idFROMproct_attribute

(6)sphinx命令扩展阅读:

sql的作用原理:

1、数据查询语言(DQL:Data Query Language):其语句,也称为“数据检索语句”,用以从表中获得数据,确定数据怎样在应用程序给出。保留字SELECT是DQL(也是所有SQL)用得最多的动词,其他DQL常用的保留字有WHERE,ORDER BY,GROUP BY和HAVING。这些DQL保留字常与其它类型的SQL语句一起使用。

2、数据操作语言(DML:Data Manipulation Language):其语句包括动词INSERT、UPDATE和DELETE。它们分别用于添加、修改和删除。

3、事务控制语言(TCL):它的语句能确保被DML语句影响的表的所有行及时得以更新。包括COMMIT(提交)命令、SAVEPOINT(保存点)命令、ROLLBACK(回滚)命令。

4、数据控制语言(DCL):它的语句通过GRANT或REVOKE实现权限控制,确定单个用户和用户组对数据库对象的访问。某些RDBMS可用GRANT或REVOKE控制对表单个列的访问。

5、数据定义语言(DDL):其语句包括动词CREATE,ALTER和DROP。在数据库中创建新表或修改、删除表(CREAT TABLE 或 DROP TABLE);为表加入索引等。

G. sphinx的原理是什么适用于所有数据库

sphinx适用于所有数据库
用户发送查询请求给数据库,数据库对sql进行分析,优化.在将优化后的sql给sphinxSE对sql进行处理,处理成适用于sphinx的命令,并将命令发送给sphinx,然后sphinx查询索引文件,对应到数据库里的相应的数据,返回结果给用户

H. 在Ubuntu下安装好sphinx 2.0之后怎么测试是否安装成功呢

sphinx 2.0安装完成的时候,会有提示信息告知你安装结果的。也可以在sphinx 2.0安装好之后,找到一并安装的php、python等多种语言的测试脚本,可以通过这些脚本来检测sphinx是否安装成功。或者直接通过 /usr/bin/indexer --all 命令来建索引从而检查sphinx的运行状况,当然建索引的前提是你的索引配置文件都已经配置ok。

I. sphinx 在 windows下到底怎么安装

一、关于Sphinx

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

一般而言,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.直接在http://www.sphinxsearch.com/downloads.html找到最新的windows版本,我这里下的是Win32 release binaries with MySQL support,下载后解压在D:\sphinx目录下;

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

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

type = mysql # 数据源,我这里是mysql
sql_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 Files\MySQL\MySQL Server 5.0\bin>mysql -uroot test<d:/sphinx/example.sql

5.建立索引

D:\sphinx\bin>indexer.exe –all
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:\sphinx\bin>

6.搜索’test’试试

D:\sphinx\bin>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:\sphinx\bin>

都所出来了吧。

6.测试中文搜索

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

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

重建索引:

D:\sphinx\bin>indexer.exe –all

搜索’中文’试试:

D:\sphinx\bin>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:\sphinx\bin>

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

<?php
require ’sphinxapi.php’;
$s = new SphinxClient();
$s->SetServer(’localhost’,3312);
$result = $s->Query(’中文’);
var_mp($result);
?>

启动Sphinx searchd服务

D:\sphinx\bin>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

J. 如何把外部文件导入sphinx

. 下载并安装python for windows: w.python.org/downloads/windows/
2.下载安装setup tools下载easy_stall.py 并运行 org/pypi/setuptools#windows-7-or-graphical-install,可以找到windows 7的下载地址
3.安装完成后,在python的scripts目录下,应该可以找到easy_install,在控制台下执行该命令在命令行输入easy_install sphinx

easy_install可以自动下载并安装sphinx以及它所依赖的其他模块。
4.安装完成后,命令行会提示Finished Processing dependencies for shinx
5.在命令行输入sphinx-build,如果在安装python时,没有设置环境变量,可能会弹出sphinx-build不是内部或者外部命令。
6.添加环境变量,将python目录下的scripts加入到环境变量的path中。再次执行会有相关信息。不用管这些,重要的是sphinx-build可用
7.找到下载的docs文档目录,如下图所示,build是我自己添加了,默认只有其他几个文件及文件夹

阅读全文

与sphinx命令相关的资料

热点内容
androidslog 浏览:38
云服务器数据盘太小 浏览:590
linux进程间socket通信 浏览:785
歌云网免费服务器 浏览:247
服务器维护买什么牌子的好 浏览:130
车用压缩机电磁离合器 浏览:550
说历史的程序员 浏览:750
哪个app可以查房子成交历史 浏览:189
这本书能让你戒烟pdf 浏览:568
饮品溯源码燕窝多少钱一盒 浏览:99
怎么建文件夹放文件 浏览:768
如何创建mc服务器地址 浏览:677
服务器怎么开通所有端口 浏览:119
程序员那么可爱分集介绍 浏览:579
vscode查看包源码 浏览:555
带命令行提示的安全模式xp 浏览:922
哪个app没有vip可以看电视 浏览:203
编程思维之我见 浏览:533
胸椎压缩性骨折手术后要吃药吗 浏览:405
python串口编程器 浏览:249