sphinx的使用

刚接触使用sphinx,读了些资料,现在就把我所理解到的记录下:


1:修改sphinx.conf文件后,需要重新建立索引,查询才会生效,所谓的全文索引查找,就是在setfilter后(相当于sql的where条件),query('content','index‘);

    (1):content代表要查询的文字。(2):index是建立的要查询的索引

   找到匹配的结果。


2:当我们使用API从sphinx执行了一个查询之后,接口会返回一个数组。在这个数组中存在total_found和total两个值。

当查询出的结果数小于sphin中配置的最大返回结果数(默认为1000)时,这两个值是相等的。

而查询出的结果数大于sphin中配置的最大返回结果数(默认为1000)时,total_found的值是在sphinx中所有满足搜索条件的结果数,而total返回的是sphin中配置的最大返回值。

因此,在分页等需要所有满足搜索条件的结果数的时候,应该使用total_found的值。


3:代码实例如下

 require(“sphinxapi.php”);              //加载类文件

$cl=new SphinxClient();               //实例化类

$cl->SetServer(‘localhost’,9312); //设置服务

$cl->SetArrayResult(true);           //设置 显示结果集方式

$cl->SetLimits(0,10);                   //同 sql语句中的LIMIT

$cl->SetSortMode(“mode”);         //排序模式 SPH_SORT_ATTR_DESC和SPH_SORT_ATTR_ASC

$result=$cl->Query(‘ff’,[索引名称可选]);                 //执行搜索

Var_dump($result);                      //输出


4:sphinx建立所以 及监听

切换到 DOS sphinx/bin 目录下

a.       建立索引

Indexer  –c  sphinx.conf  索引名称/–all (–all参数是建立所有索引)

完成后提示如下:

total 535600 docs, 10707632 bytes

total 34.323 sec, 311958 bytes/sec, 15604.27 docs/sec

total 5 reads, 0.282 sec, 45592.6 kb/call avg, 56.4 msec/call avg

total 547 writes, 12.172 sec, 1017.0 kb/call avg, 22.2 msec/call avg

b.       建立完成后

可以执行 search [–c] sphinx.conf 搜索内容 (-c参数:是否允许模糊搜索)

c.       监听端口

Searchd

运行后 提示

listening on all interfaces, port=9312

accepting connections

监听成功后 既可以运行PHP程序 进行 搜索


5:

属性 描述
sql_attr_uint 和sql_attr_bigint 32 位无符号整数值和 64 位有符号整数值。可对所有整数数据库字段和 DATE 使用这两种类型。
sql_attr_float 32 位浮点值。如果您想要存储地理坐标,可使用此属性类型。还要注意的是,如果您需要更高的精确度,则没有解决方法;字段四舍五入到七位小数。
sql_attr_bool 一个布尔型(单个位)值,类似于 MySQL 的 tinyint 值。
sql_attr_timestamp 一种 UNIX 时间戳,可表示从 1970-01-01 到 2038-01-19 的日期/时间值。您在 Sphinx 中无法直接使用 DATE 或 DATETIME 列类型。您必须使用 UNIX_TIMESTAMP() 函数将它们转换为时间戳。如果您仅需要日期,可使用 TO_DAYS() 函数将 DATE 字段转换为一个整数。
sql_attr_string 和sql_field_string 字符串(很明显!),但前者仅用于检索,而后者可作为全文本被索引。

6:

如何改变Sphinx搜索的Total最大限制值

Sphinx搜索匹配的总数默认为1000。不过,你可以修改成任意值。官方建议是1,000 - 10,000 之间。

修改Sphinx搜索匹配总数的方法

假如你希望搜索匹配总数为 8000

1) Sphinx.conf(修改配置文件需要重新建立索引)
max_matches = 8000 <-修改成你希望的值

2)sphinxapi.php
 $this->_maxmatches = 8000; //改成希望的值

3)Sphinx客户端调用
sphinxClient.SetLimits(0,10, 8000); <-修改第三个参数


sphinx服务启动



1 down vote accepted

You'll need to call indexer on the new index to create it and then --rotate to update it.

So it would be something like

indexer --config /path/to/config.conf indexname

And then when you just want to update your indexes

indexer --config /path/to/config.conf --rotate --all

This will create a temporary copy of each index and replace the old ones when finished. For more info on what actually happens see http://sphinxsearch.com/docs/manual-0.9.9.html#ref-indexer

On the other error your getting Do

ps aux | grep searchd

if it returns no results, then remove /usr/local/sphinx/var/log/searchd.pid and start searchd again


1 down vote accepted

You'll need to call indexer on the new index to create it and then --rotate to update it.

So it would be something like

indexer --config /path/to/config.conf indexname

And then when you just want to update your indexes

indexer --config /path/to/config.conf --rotate --all

This will create a temporary copy of each index and replace the old ones when finished. For more info on what actually happens see http://sphinxsearch.com/docs/manual-0.9.9.html#ref-indexer

On the other error your getting Do

ps aux | grep searchd

if it returns no results, then remove /usr/local/sphinx/var/log/searchd.pid and start searchd again

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值