PHPer成长点滴

迅搜的使用

2017-11-11  本文已影响11人  炜哲1120

1.迅搜的安装

运行下面指令下载、解压安装包

wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2

tar -xjf xunsearch-full-latest.tar.bz2

执行安装脚本,根据提示进行操作,主要是输入 xunsearch 软件包的安装目录,强烈建议单独 规划一个目录,而不是混到别的软件目录中。

cd xunsearch-full-1.3.0/

sh setup.sh

执行安装脚本时,提示是否安装在默认的位置,默认即可

安装完成后,提示如下

安装完成后的提示

启动xunsearch

/usr/local/xunsearch/bin/xs-ctl.sh restart

/usr/local/xunsearch/bin/xs-ctl.sh start

2.将启动命令添加到开机启动脚本中,以便每次服务器重启后能自动启动搜索服务程序, 在 Linux 系统中您可以将脚本指令写进 /etc/rc.local 即可。

将启动脚本加入rc.local

3.安装后迅搜后,需要在/usr/local/xunsearch/sdk/php/app/内新建一个ini配件文件。

如:

project.name = laonanren

server.index =8383

server.search =8384

[article_id]

type = id

[title]

type = title

weight=1000

[cat_id]

[bclassid]

[user_id]

[titleimg]

[add_time]

index = self

[keywords_id]

index = self

[desc]

type=body

[status]

index = self

[pagenum]

index = self

[author]

[keywords]

index = mixed

[about]

index = mixed

[url]

index = self

[vcount]

[mcount]

4.在PHP中执行初始化操作。

include '/usr/local/xunsearch/sdk/php/lib/XS.php';

$xs = new \XS('laonanren');

$index = $xs->index; // 获取 索引对象

// $xs->index->clean();

$doc = new \XSDocument;

$pertime = 200;

for($i = 1;$i<10000;$i++){

    $map = array();

    $map['status'] = 1;

    $offset =($i - 1) * $pertime;

    $articlelist = M('Article')->where($map)->limit($offset,$pertime)->field('article_id,title,cat_id,bclassid,user_id,titleimg,keywords_id,desc,status,is_del,origine,pagenum,author,keywords,url,from,vcount,add_time,edit_time')->select();

if (!$articlelist) {

    break;

}

foreach ($articlelist as $key => $info) {

    $doc->setFields($info);

    $index->update($doc);

    echo "第".$k++."次";

}

    usleep(5);

}

echo"ok!";

上一篇 下一篇

猜你喜欢

热点阅读