coreseek里not in 和 关键词为空怎么处理

coreseek里not in 和 关键词为空怎么处理

本文目录

  • coreseek里not in 和 关键词为空怎么处理
  • coreseek 索引 哪个文件
  • coreseek(sphinx) 如何实现 like 模糊查询
  • 在thinkphp下怎么使用coreseek
  • CoreSeek怎么样才能不分词
  • 谁有coreseek Windows安装
  • sphinx/coreseek如何及时删除索引里的数据呢
  • coreseek 安装完成后 怎么调用接口
  • coreseek setsortmode可以设置多个吗

coreseek里not in 和 关键词为空怎么处理


默认关键次为空是是没有结果的,如果要展现所有信息,需要修改匹配模式为SPH_MATCH_FULLSCAN
$cl-》setMatchMode(SPH_MATCH_FULLSCAN);

coreseek 索引 哪个文件


coreseek实时索引更新有两种选择:
1.使用基于磁盘的索引,手动分区,然后定期重建较小的分区(被称为“增量”)。通过尽可能的减小重建部分的大小,可以将平均索引滞后时间降低到30~60秒.在0.9.x版本中,这是唯一可用的方法。在一个巨大的文档集上,这可能是最有效的一种方法
2.版本1.x(从版本1.10-beta开始)增加了实时索引(简写为Rt索引)的支持,用于及时更新全文数据。在RT索引上的更新,可以在1~2毫秒(0.001-0.002秒)内出现在搜索结果中。然而,RT实时索引在处理较大数据量的批量索引上效率并不高。
这篇我们只要是增量索引
基本思路是设置两个数据源和两个索引,对很少更新或根本不更新的数据建立主索引,而对新增文档建立增量索引
配置文件中定义了主索引和增量索引之后,不能直接用indexer –config d:\coreseek\csft.conf –all,再添加数据到数据库中,再用indexer –config d:\coreseek\csft.confg main delta –rotate来弄(我居然这样弄了两次)。正确步骤为:
1.创建主索引:indexer –cd:\coreseek\csft.conf --all
2.添加数据
3.再创建增量索引:indexer –cd:\coreseek\csft.conf delta --rotate
4.合并索引:indexer –cd:\coreseek\csft.conf --merge main delta –rotate(为了防止多个关键字指向同一个文档加上--merge-dst-range deleted 0 0)

coreseek(sphinx) 如何实现 like 模糊查询


1、sphinx的两个主要进程indexer和searchd。
indexer任务是从数据库(或者其他的数据源)收集原始的数据,然后建立相应的索引。
searchd则是通过读取indexer建立的索引来响应客户端的请求。
2、sphinx工作前提:配置文件修改
a、需要让其获取数据源从何而来(即:配置source信息)
b、建立索引,对数据源的哪部分数据进行索引等详细信息(即:indexer的所有信息)
c、执行indexer生产索引,最用才启用searchd服务
3、应用主要是通过api接口实现,支持php、perl、python及ruby等语言调用。

在thinkphp下怎么使用coreseek


首先我们把coreseek下载好,命名为coreseek,我们找到coreseek/etc中的csft_mysql.conf修改这个配置文件。
#源定义
source lemai
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = 123
sql_db = lemai
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, title,content,name FROM shop
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
sql_attr_uint = sid #从SQL读取到的值必须为整数
sql_attr_timestamp = time #从SQL读取到的值必须为整数,作为时间属性
sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集
sql_query_info = SELECT * FROM shop WHERE name=$id #命令行查询时,从数据库读取原始数据信息
}
#index定义
index lemai
{
source = lemai #对应的source名称
path = var/data/mysql #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0
#中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
#charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
charset_dictpath = C:/AppServ/www/thinkphp/ThinkPHP/Extend/Vendor/Coreseek/etc/ #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...
charset_type = zh_cn.utf-8
#charset_table =
ngram_len = 0
}
#全局index定义
indexer
{
mem_limit = 128M
}
#searchd服务定义
searchd
{
listen = 9312
read_timeout = 5
max_children = 30
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
pid_file = var/log/searchd_mysql.pid #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
log = var/log/searchd_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
query_log = var/log/query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
}
然后把coreseek拷贝一份到thinkphp的核心文件Extend/Vendor下.
打开cmd cd到coreseek
bin\indexer -c etc\csft_mysql.conf (mysql,等)数据库名 创建索引
创建完之后我们可以在var\data下看到一堆文件,此时说明创建成功
bin\searchd -c etc\csft_mysql.conf --console 启动进程
(检查端口9312是否有这个进程,有就OK)
命令行查询
echo 一号店 |iconv -f gbk -t utf-8 | search -c etc\csft_mysql.conf --stdin | iconv -f utf-8 -t gbk 中文索引查询
然后就可以在控制器中进行PHP连接sphinxapi进行测试了
Vendor(’Coreseek.api.sphinxapi’);
//加载第三方扩展包的文件 文件名不包含class
$db = new PDO(’mysql:host=localhost;port=3306;dbname=lemai’, ’root’, ’123’, array( PDO::MYSQL_ATTR_INIT_COMMAND =》 ’SET NAMES UTF8’));
//实例化PDO
$spx = new SphinxClient();
//实例化SphinxClient
$spx -》 SetServer(’127.0.0.1’,9312);
$spx-》SetConnectTimeout ( 3 );
$spx-》SetArrayResult ( true );
$spx -》 SetMatchMode(SPH_MATCH_ANY);
$result = $spx -》 query(’1’,’*’);
$ids = join(“,“,array_keys($result[’matches’]));
$sql = “SELECT * FROM shop where id in ({$ids})“;
$stmt = $db-》query($sql);
$r = $stmt-》FETCHALL(PDO::FETCH_ASSOC);
echo “《pre》“;
var_dump($r);
以下是我的实例代码 包括sphinx分页
class IndexAction extends Action {
public function index(){
header(“Content-type:text/html;charset=utf-8“);
//设置字符集

$keyword = $_GET[’kw’];
Vendor(’Coreseek.api.sphinxapi’);
//加载第三方扩展包的文件 文件名不包含class
$db = M();
$spx = new SphinxClient();
//实例化SphinxClient

$spx -》 SetServer(’127.0.0.1’,9312);
//设置ip和端口

$spx-》SetConnectTimeout ( 3 );
//设置超时时间
$spx-》SetArrayResult ( true );
if(strlen($keyword)》=18){
$spx -》 SetMatchMode(SPH_MATCH_ALL);//如果用户查询字符大于=18个匹配有查询词
}else{
$spx -》 SetMatchMode(SPH_MATCH_ANY);//匹配查询词中的任意一个
}
//------
$limit = 12;//每页要显示的数量
$page = $_GET[’page’]》1 ? $_GET[’page’] : 1;
//GET值不为1 则按1算

//$spx-》setLimits(0,12);
$off = ($page-1)*$limit;
$spx-》SetLimits( $off, $limit);
//设置分页

$result = $spx -》 query(“{$keyword}“,’*’);

/*
* 取出matches中的id,组成字符串
*/
$str = ’’;
foreach($result[’matches’] as $rrs){
$str.=$rrs[’id’].’,’;
}
$ids = rtrim($str,’,’);

//操作数据库
$sql = “SELECT * FROM shop where id in ({$ids})“;
$stmt = $db-》query($sql);

$opts = array(
“before_match“=》“《span style=’color:red’》“,//添加样式
“after_match“=》“《/span》“
);
foreach($stmt as $st){
$shop_all = $spx-》buildExcerpts($st,’lemai’,$keyword,$opts);
}

$num = $result[’total’];
$count =ceil($result[’total’]/12);//查出sphinx搜索总数 得出该关键词分页数
$pagenum = $_GET[’page’]》1?$_GET[’page’]:1;
$this-》assign(’pagenum’,$pagenum);
$this-》assign(’num’,$num);
$this-》assign(’count’,$count);
$this-》assign(’shop_all’,$shop_all);
$this-》assign(’keyword’,$keyword);
$this-》display(“seek“);
}
}

CoreSeek怎么样才能不分词


sphinx在此处下载:
http://sphinxsearch.com/downloads/release/自持中文分词的包叫做coreseek,其实就是带了中文分词插件的sphinx,在此处下载:http://www.coreseek.cn/稳定版3.2.14
先写个结论,sphinx本身是可以支持中文搜索的,只是不支持中文分词,需要安装中文分词插件,coreseek就是一个打包了mmseg中文分词插件和sphinx源码的安装包
目前coreseek已经很久不更新了,稳定版3.2.14内带的的sphinx还是 0.9.9 release版本的;而sphinx可以通过设置为“一元切分模式”来支持搜索中文
在实际使用中,搜索非中文的话,sphinx比coreseek要快;搜索短中文字符串的话,开启了“一元切分模式”的sphinx比coreseek要快;只有在搜索长中文字串时,coreseek的分词优势才能显现,比sphinx要快
所以根据你的应用场景来选择用哪个,如果是索引英文、数字、字符较多的数据,就用源生sphinx;如果是索引中文非常多非常长的数据,还是用coreseek
更多问题到问题求助专区(http://bbs.houdunwang.com/)

谁有coreseek 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.直接在找到最新的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_dump($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

sphinx/coreseek如何及时删除索引里的数据呢


当我们删除数据时,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:\data\stopwords.txt
#wordforms =G:\data\wordforms.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.Sphinx api 类(位于coreseek源码包里的csft里的api文件夹里有一个sphinxapi.php,使用的时候包含这个php文件即可)
我们要使用sphinx需要做以下几件事:
1.首先要有数据
2.建立sphinx配置文件
3.生成索引
4,启动searchd 服务进程,并开启端口9312
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的方法和代码了

coreseek setsortmode可以设置多个吗


sphinx coreseek按照匹配度SPH_SORT_RELEVANCE排序,那么当匹配度一样时,就会按照id正需排列,现在要求按照时间倒序排列,最后用自定义排序解决了,$cl-》SetSortMode(SPH_SORT_EXTENDED, “key_id desc“);

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部