1.安装

注1:既然你已经选择了xunsearch,肯定已经知道了它只能在linux上安装使用,所以你需要有linux相关的只是储备。
注2:在安装之前请务必确保你的电脑上有g++与zlib这个模块,否则安装不会成功的。

下载与解包:
我就下载到/usr/local这个目录:
先进入目录:cd /usr/local
目录
执行:wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2 开始下载
wget
执行ls查看是否下载完成:
ls
由于我之前下载过了,所以这里有很多个安装包,读者请忽视。接下来解包:
执行tar -xjf xunsearch-full-latest.tar.bz2
这里写图片描述
出现图片的效果说明解压缩成功了。再次查看目录:
这里写图片描述
可以看到多了一个文件夹xunsearch-full-1.4.11
进入该目录:
这里写图片描述
准备开始安装:
sh setup.sh
执行了该命令后按照提示选择目录,一般默认目录是xunsearch,如果需要修改到其他目录必须使用绝对路径。
安装过程中可能出现问题,常见的有以下两种:

Checking scws … no Installing scws (1.2.3) … Extracting scws
package … Configuring scws … Compiling & installing scws …
Checking scws dict … no Extracting scws dict file … Checking
libuuid … no, try to install it Extracting libuuid package …
Configuring libuuid … Compiling & installing libuuid … Checking
xapian-core-scws … no Installing xapian-core-scws (1.2.22) …
Extracting xapian-core-scws package …

Configuring xapian-core-scws …

checking whether g++ accepts -g… no checking dependency style of g++… none checking whether g++ is a working C++ compiler… no
configure: error:
*** You need a working C++ compiler to compile Xapian, but configure failed to
*** find one. If you have a working C++ compiler, you can tell configure where

*** to find it by invoking it like so:


*** ./configure CXX=/opt/bin/c++

----- ERROR: failed to configure xapian-core-scws, see ‘setup.log’ for more detail

出现这种情况是因为没有安装g++
yum install gcc-c++
不同发行版的linux执行不同的命令下载。
第二种:

Checking scws … 1.2.3 Checking scws dict … ok Checking libuuid …
yes: /usr/local/xunsearch Checking xapian-core-scws … no Installing
xapian-core-scws (1.2.22) … Extracting xapian-core-scws package …
Configuring xapian-core-scws …
----- checking whether strerror_r is declared… yes checking for strerror_r… yes checking whether strerror_r returns char *… yes
checking whether sys_errlist is declared… yes checking whether
_sys_errlist is declared… yes checking whether sys_nerr is declared… yes checking whether _sys_nerr is declared… yes checking
for working ISO C90 conforming snprintf… snprintf checking for
zlib.h… no configure: error: zlib.h not found - required for brass,
chert and flint (you may need to install the zlib1g-dev or zlib-devel
package)
----- ERROR: failed to configure xapian-core-scws, see ‘setup.log’ for more detail

这是因为没有安装zlib模块:yum install zlib-devel
(不同的操作系统执行不同的命令下载)

[XSException] …/lib/XS.php(2551): Connection refused(C#111,
localhost:8383)
0 …/lib/XS.php(2363): XSServer->connect()
1 …/lib/XS.php(2348): XSServer->open(‘8383’)
2 …/lib/XS.php(370): XSServer->__construct(‘8383’, Object(XS))
3 …/lib/XS.php(262): XS->getIndex()
4 Indexer.php(157): XSComponent->__get(‘index’)
5 {main}

安装成功后可以直接按照屏幕提示启动,也可以到bin目录启动,操作如下:
启动

2.启动

启动的方式有四种:

bin/xs-ctl.sh -b local start // 监听在本地回环地址 127.0.0.1 上 bin/xs-ctl.sh -b inet start // 监听在所有本地 IP 地址上
bin/xs-ctl.sh -b a.b.c.d start // 监听在指定 IP 上
bin/xs-ctl.sh -b unix start // 分别监听在 tmp/indexd.sock tmp/searchd.sock

因为我这里要演示的是在windows上使用xunsearch sdk所以我选择第二种启动方式,监听在所有的本地的ip地址上,启动成功后的效果如图:
启动
可以看下端口(8383,8384)是否开了:netstat -anpt

3.体验demo项目

个人认为xunsearch官方文档在这一部分写的还算是比较详细,
体验demo项目官方文档
我就贴几张操作的演示图片就行:
1
屏幕提示让我们输入数据,这里官网给我们了几条测试数据,我们直接复制粘贴录进去就行了:
这里写图片描述
数据导入成功过后可以调用Quest.php这个文件进行查询操作。
xunsearch官方文档一直被人们诟病的原因可能就是因为,它只是说了该怎么做,并没有说为什么这么做或者是结构比较散乱。
我在这里大概的解释一下吧:
xunsearch是一个开源的搜索引擎解决方案,二搜索引擎最关键的就是索引的建立,而我们刚刚调用Indexer.php就是实现了索引的建立,索引是建立为一个单独的索引文件的(怎么实现的咱们不去深究,你就可以把整个Indexer.php文件理解为一个函数,然后传进去特定的参数他就会执行特定的动作),而Quest.php自然就是查询功能了。

4.windows上使用xunsearch sdk

读者想要开发自己的搜索程序,就必须建立一个自己的配置文件,配置文件的配置是xunsearch的核心。
下面我将根据一个实例来讲解如何配置,在这之前读者需要先了解xunsearch的配置文件:
demo配置文件详解–官方文档
这是我的一个配置文件:
配置文件
我的项目叫做fs,编码为utf-8,然后由于我要在windows上使用xunsearch提供的服务,所以server.index与server.search的地址都需要填写xunsearch所在主机的ip地址与端口(这个如果填写错误就不能用),当然你如果是在一台主机上使用直接写localhost就行。

然后下面的id,title,resource,origin,year,type这些字段都是我自己定制的,读者可以根据自己的数据进行设置,具体参考官方文档,我就是根据我的数据库定制的,并且设置了哪些字段可以被搜索之类的:
数据库

配置完了,下面就给我们的项目建立索引了,建立索引之前也提到过了,但是我们是手动录入的数据,现在我们是要从数据库导入数据(mysql),如果你的数据库和xunsearch服务端在一台机器上,
参考官方文档:

清空 demo 项目的索引数据
util/Indexer.php --clean demo

导入 JSON 数据文件 file.json 到 demo 项目
util/Indexer.php --source=json demo file.json

导入 MySQL 数据库的 dbname.tbl_post 表到 demo 项目中,并且平滑重建
util/Indexer.php --rebuild --source=mysql://root:pass@localhost/dbname --sql=“SELECT * FROM tbl_post” --project=demo

查看 demo 项目在服务端的相关信息 util/Indexer.php --info -p demo

强制刷新 demo 项目的搜索日志 util/Indexer.php --flush-log --project demo

强制停止重建 util/Indexer.php --stop-rebuild demo

如果不是在同一台主机记得把localhost改为相应的ip地址+端口,不然不能使用。

windows上安装xunsearch的sdk:
现在我们的工作完成一大半了,但是之前其实都是准备工作,想要在windows上使用xunsearch服务必须在windows上单独下载它的sdk:
sdk下载
sdk下载好了过后放在你要开发的搜索应用的目录下,这样你才能使用,例如我的:
目录
然后还有最后一步,你的linux上的配置文件,必须和windows上的配置文件相同,例如我的:
fs
现在所有配置都完了,你就可以放心的使用xunsearch了,你问我该怎么使用,送你一份官方文档:
xunsearch-php-sdk使用官方文档


每天进步一点点


GitHub 加速计划 / li / linux-dash
10
2
下载
A beautiful web dashboard for Linux
最近提交(Master分支:20 天前 )
186a802e added ecosystem file for PM2 5 年前
5def40a3 Add host customization support for the NodeJS version 5 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐