coreseek安装与简单实用

安装环境

  • 系统环境

    • centos7.2
    • 1核2G
  • 软件环境

安装mmseg

  • 更新依赖包和安装编译环境
yum -y install m4 autoconf automake libtool
yum -y install gcc gcc-c++ wget
yum -y install mysql-devel

安装coreseek

tar -xzvf coreseek-3.2.14.tar.gz
cd coreseek-3.2.14
cd mmseg-3.2.14/
./bootstrap
./configure --prefix=/usr/local/mmseg3
make
make install cd ../csft-3.2.14/
sh buildconf.sh
./configure --prefix=/usr/local/coreseek --without-python --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql --host=arm
make
make install

在安装csft的过程中出现了三种错误情况,错误情况如下错误记录,可以参考修改即可

配置coreseek配置文件

配置文件主要修改的几个地方如下,具体的修改信息请参见 coreseek配置文件 目录的进行配置

source src1
{
type = mysql #数据库类型
sql_host = localhost # MySQL主机IP
sql_user = root # MySQL用户名
sql_pass = 123 # MySQL密码
sql_db = test # MySQL数据库
sql_port = 3306 # MySQL端口
sql_sock = /tmp/mysql.sock #如果是linux下需要开启,指定sock文件
sql_query_pre = SET NAMES UTF8 # MySQL检索编码
sql_query_pre = SET SESSION query_cache_type=OFF #关闭缓存
sql_query = \ #获取数据的SQL语句
SELECT id, title, content FROM post
#sql_attr_uint = group_id #对排序字段进行注释
#sql_attr_timestamp = date_added #对排序字段进行注释
sql_query_info = SELECT * FROM post WHERE id=$id
} #这行不需要修改
source srclthrottled:srcl #继承主数据源
主数据源索引:
index text1
{
source = src1 #索引源声明
charset_type = utf-8 #数据编码(设置成utf8)
charset_table = #上面指定了utf-8,这里需要开启
}
增量索引
index testlstemmed:test1 #先进行注释
index distl #分布式也注释掉
索引器设置
indexer
{
mem_limit = 256M # 内存大小限制 默认是 32M, 推荐为 256M
} #其他用默认即可
sphinx服务进程searchd的相关配置
searchd {
} #全部用默认的就可以了

除了上述的配置项外还需要单独配置几项(如果你是安装的sphinx则进行上述配置即可,如果是coreseek则还需要配置下述内容)

index test1
{
#stopwords = G:\data\stopwords.txt
#wordforms = G:\data\wordforms.txt
#exceptions = /data/exceptions.txt
#charset_type = sbcs
添加下面这两行,意思是把中文分词加入到配置文件中
charset_type = zh_cn.utf-8
charset_dictpath = /usr/local/mmseg/etc/ #你安装mmseg的目录
}

数据库操作

// 创建数据库
create database test;
// 创建数据表
userinfo | CREATE TABLE `userinfo` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`name` varchar(10) NOT NULL,
`age` int(3) NOT NULL,
`sex` enum('女','男') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4
// 插入数据
INSERT INTO `userinfo` VALUES (1,'张三',12,'女'),(2,'李四',13,'男'),
(3,'小明',12,'女'),(4,'小红',13,'女'),(5,'小四',12,'女'),(6,'章泽天',13,'女');

创建索引数据(indexer)

// 第一次创建索引
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all
// 第二次创建所以(当我们第一次创建索引之后,对数据表做了新的操作再按照上面的方式生成索引是会多增加一个参数)
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf -rotate option

如果上述的操作执行正确,则会提示如下信息

Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file '/usr/local/coreseek/etc/csft.conf'...
WARNING: no such index '-rotate', skipping.
WARNING: no such index 'option', skipping.
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg

测试索引数据(search)

/usr/local/coreseek/bin/search '小'

正常情况下会出现下述信息

Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file '/usr/local/coreseek/etc/csft.conf'...
index 'test1': query '小 ': returned 3 matches of 3 total in 0.004 sec displaying matches:
1. document=3, weight=1
2. document=4, weight=1
3. document=5, weight=1 words:
1. '小': 3 documents, 3 hits

启动searchd服务

该服务是可以在/usr/local/coreseek/etc/csft.conf文件中的searchd配置项中配置,默认服务的端口已经配置,可以不单独做配置

// 启动服务
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf
// 检测服务启动情况
[root@test ~]# netstat -anp | grep 9312
tcp 0 0 0.0.0.0:9312 0.0.0.0:* LISTEN 31672/searchd

创建测试代码

测试代码可以参见分享文件中的 测试代码 目录

require './api/sphinxapi.php';
$sphinx = new SphinxClient();
$sphinx->SetServer('127.0.0.1', 9312);
$sphinx->SetArrayResult(true);
$sphinx->SetMatchMode(SPH_MATCH_ALL);
$sphinx->SetSortMode(SPH_SORT_RELEVANCE);
$result = $sphinx->query('小', '*');
var_dump($result);

查询出的结果如下

array(10) {
["error"]=>
string(0) ""
["warning"]=>
string(0) ""
["status"]=>
int(0)
["fields"]=>
array(3) {
[0]=>
string(4) "name"
[1]=>
string(3) "age"
[2]=>
string(3) "sex"
}
["attrs"]=>
array(0) {
}
["matches"]=>
array(3) {
[0]=>
array(3) {
["id"]=>
int(2)
["weight"]=>
string(1) "1"
["attrs"]=>
array(0) {
}
}
[1]=>
array(3) {
["id"]=>
int(3)
["weight"]=>
string(1) "1"
["attrs"]=>
array(0) {
}
}
[2]=>
array(3) {
["id"]=>
int(4)
["weight"]=>
string(1) "1"
["attrs"]=>
array(0) {
}
}
}
["total"]=>
string(1) "3"
["total_found"]=>
string(1) "3"
["time"]=>
string(5) "0.003"
["words"]=>
array(1) {
["小"]=>
array(2) {
["docs"]=>
string(1) "3"
["hits"]=>
string(1) "3"
}
}
}

coreseek错误记录

安装coerseek问题一

cd ../csft-3.2.14/      

sh buildconf.sh

./configure --prefix=/usr/local/coreseek --without-python --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql --host=arm

 vi src/sphinxexpr.cpp  #然后将所有的T val = ExprEval ( this->m_pArg, tMatch ).....修改为T val =this->ExprEval ( this->m_pArg, tMatch ),共有三处。

安装coreseek错误二

make[2]: *** [tokenizer_zhcn.o] Error 1
make[2]: Leaving directory `/home/zyf/zyfwork/csft3.1b3/src’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/zyf/zyfwork/csft3.1b3/src’
make: *** [all-recursive] Error 1 /usr/local/sphinx/src/sphinx.cpp:15557: undefined reference to `libiconv_open’
libsphinx.a(sphinx.o)(.text+0x53a01):/usr/local/sphinx/src/sphinx.cpp:15575: undefined
reference to `libiconv’
libsphinx.a(sphinx.o)(.text+0x53a28):/usr/local/sphinx/src/sphinx.cpp:15581: undefined
reference to `libiconv_close’
collect2: ld returned 1 exit status
make[2]: * [indexer] Error 1
make[2]: Leaving directory `/usr/local/sphinx/src’
make[1]: * [all] Error 2
make[1]: Leaving directory `/usr/local/sphinx/src’
make: * [all-recursive] Error 1 修改 configure 文件把 #define USE_LIBICONV 0 最后的数值由1改为0

安装coreseek问题三

db_interface_mysql.h:32:25: 致命错误:mysql/mysql.h:没有那个文件或目录
// ubuntu系统解决方案
sudo apt-get install libmysqlclient-dev
// centos7解决方案
sudo yum install mysql-devel

参考链接

参考链接一

参考链接二

参考链接三

coreseek额外说明

安装路径

/usr/local/coreseek

配置目录

/usr/local/coreseek/etc/

执行程序目录

/usr/local/coreseek/bin/

配置文件说明

进入配置目录,你会找到如下几个文件

-rw-r--r--. 1 root root   905 10月 13 21:27 example.sql
-rw-r--r--. 1 root root 18954 10月 13 21:27 sphinx.conf.dist
-rw-r--r--. 1 root root 956 10月 13 21:27 sphinx-min.conf.dist

将sphinx.conf.dist文件复制一份名为csft.conf即可.其余文件可以不管.

执行程序说明

进入执行程序目录可以看到如下几个文件,具体参考请见sphinx文档

-rwxr-xr-x. 1 root root 7032560 10月 13 21:27 indexer // 生成索引程序
-rwxr-xr-x. 1 root root 6650552 10月 13 21:27 indextool // 调试程序
-rwxr-xr-x. 1 root root 6740544 10月 13 21:27 search // 搜索程序
-rwxr-xr-x. 1 root root 7970448 10月 13 21:27 searchd // 提供客户端查询索引服务
-rwxr-xr-x. 1 root root 6370256 10月 13 21:27 spelldump // 提取字典内容

分享文件目录说明

├── api.zip // coreseek类文件(该文件和测试代码目录下的api.zip是一样的)
├── coreseek-3.2.14.tar.gz // coreseek安装程序文件
├── coreseek配置文件
│   └── csft.conf // 上述 配置coreseek配置文件 步骤中提交到的配置文件
├── 测试代码
│   ├── api.zip
│   └── index.php // 测试代码
└── 测试数据库
└── test.sql // 测试数据库

lnmp+coreseek实现站内全文检索(安装篇)的更多相关文章

  1. 站内全文检索服务来了,Xungle提供免费全文检索服务

    免费站内全文检索服务来了,是的,你没听错.全文检索相信大家已经不太陌生,主流检索服务有sphinx.xunsearch等,但这些都受服务器限制,对于中小站长尤其是没有服务器实现就困难了,随着数据量的增 ...

  2. WordPress安装篇(4):YUM方式安装LNMP并部署WordPress

    YUM方式安装软件的优点就是简单.方便.快捷,本文介绍在Linux上如何使用YUM方式快速安装LNMP并部署WordPress.使用Linux CentOS 7.9 + Nginx 1.18 + My ...

  3. WordPress安装篇(5):源码编译安装LNMP并部署WordPress

    与YUM方式安装相比,源码编译安装方式更灵活,安装过程中能自定义功能和参数,特别是在批量部署服务器又要求软件版本及配置一致时,源码编译安装的优势很明显.本文介绍如何通过源码编译方式安装Nginx1.1 ...

  4. 一步步开发自己的博客 .NET版(5、Lucenne.Net 和 必应站内搜索)

    前言 这次开发的博客主要功能或特点:    第一:可以兼容各终端,特别是手机端.    第二:到时会用到大量html5,炫啊.    第三:导入博客园的精华文章,并做分类.(不要封我)    第四:做 ...

  5. 借助 Lucene.Net 构建站内搜索引擎(上)

    前言:最近翻开了之前老杨(杨中科)的Lucene.Net站内搜索项目的教学视频,于是作为老杨脑残粉的我又跟着复习了一遍,学习途中做了一些笔记也就成了接下来您看到的这篇博文,仅仅是我的个人笔记,大神请呵 ...

  6. 借助 Lucene.Net 构建站内搜索引擎(下)

    前言:上一篇我们学习了Lucene.Net的基本概念.分词以及实现了一个最简单的搜索引擎,这一篇我们开始开发一个初具规模的站内搜索项目,通过开发站内搜索模块,我们可以方便地在项目中集成站内搜索功能.本 ...

  7. es简单打造站内搜索

    最近挺忙的,在外出差,又同时干两个项目.白天一个晚上一个,特别是白天做的项目,马上就要上线了,在客户这里 三天两头开会,问题很多真的很想好好静下来怼代码,半夜做梦都能fix bugs~ 和客户交流真的 ...

  8. hexo干货系列:(五)hexo添加站内搜索

    前言 本来想用百度站内搜索,但是没成功,所以改用swiftype,用起来还是很棒的,这里分享一下我的安装步骤 正文 注册 去swiftype官网注册个账号,然后登陆,对了不要去在意30天试用,30天过 ...

  9. WordPress安装篇(3):用宝塔面板在Linux上安装WordPress

    前面的文章已经介绍了如何在Windows环境安装WordPress,这篇文章来介绍在Linux环境怎样快速安装WordPress.大家都知道,Linux系统相对于Windows系统而言占用资源更少.更 ...

随机推荐

  1. mac下安装elasticsearch报错Exception BindTransportException[Failed to bind to [9300-9400]]

    解决办法:进入 config目录下 修改 vim elasticsearch.xml network.host设置为 0.0.0.0 即可外网访问.

  2. Spring MVC基本配置和实践(一)

    一.Spring MVC介绍 1. Spring MVC是什么? The Spring Web MVC framework和Struts2都属于表现层的框架,它是Spring框架的一部分,我们可以从S ...

  3. git操作合集

    目录 安装 下载 本地配置 创建用户凭证ssh 忽略文件 基础操作 新建仓库 克隆仓库 获取更新 推送更新 查看历史 版本回退 分支 别名 linux服务器 疑难问题 清除历史大文件 安装 下载 下载 ...

  4. Windows Azure系列公开课 - 第二课:为什么选择Windows Azure(下)

    Windows Azure中有什么? |基础结构 Windows Azure能够根据您企业的需求提供最适合的基础结构,并且在业务发展或精简时能够根据变化的需求及时的做出改变.您可以将Windows A ...

  5. iOS 滑动比较

    对iOS手机进行滑动操作进行总结:1.mobile:scroll向下滚动整个屏幕driver.execute_script('mobile: scroll', {'direction': 'down' ...

  6. 使用UEFI+GPT模式安装Windows

    一.硬盘分区 分区还是用PE下最常用的DiskGenius,可直接使用"快速分区"功能对硬盘进行分区.分区表类型选择GUID,勾选建立ESP分区.ESP分区非常重要,用于存放系统引 ...

  7. 两天学会css基础(二)

    接上一篇博客,还有css中的两个重要知识点没有说到,就是元素的浮动与定位. 第三部分:元素的浮动与清除 这部分的内容之前的博客已总结过.请查看css中的浮动与三种清除浮动的方法这篇文章. 浮动在网页中 ...

  8. hdu 5521 Meeting(最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 题意:有1-n共n个点,给出m个块(完全图),并知道块内各点之间互相到达花费时间均为ti.已知两 ...

  9. BZ2763: [JLOI2011]飞行路线

    Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并 ...

  10. Kali-linux使用Wifite破解无线网络

    一些破解无线网络程序是使用Aircrack-ng工具集,并添加了一个图形界面或使用文本菜单的形式来破解无线网络.这使得用户使用它们更容易,而且不需要记住任何命令.本节将介绍使用命令行工具Wifite, ...