ubuntu12.04 安装 coreseek 4.1beta (转) ubuntu12.04 安装 coreseek 4.1beta (转)

coreseek安装需要预装的软件:

shell>apt-get install make gcc g++ automake libtool m4 autoconf mysql-client libmysqlclient15-dev libxml2-dev libexpat1-dev

 

##切换到root用户,确保拥有完整的权限来安装软件

$ su root

$ cd coreseek-4.1-beta

##中文测试环境检查:

$  locale

##以下为核心项,locale为zh_CN.UTF-8,就可以正常显示和输入中文;

##如果不能正常显示中文,则后面的中文测试部分无法正常进行,但不会影响coreseek的实际功能;

LANG=zh_CN.UTF-8

LC_ALL="zh_CN.UTF-8"

##确保可以正常显示,否则请检查当前环境的locale配置,以及当前环境或者客户端已设置好支持UTF-8中文字符显示

$ cat testpack/var/test/test.xml

##安装coreseek开发的mmseg,为coreseek提供中文分词功能

$ cd mmseg-3.2.14

##ubuntu环境下,需要使用ACLOCAL_FLAGS="-I /usr/share/aclocal" ./bootstrap

$ ./bootstrap

$ ./configure --prefix=/usr/local/mmseg3

$ make && make install

##如果提示libtool: unrecognized option `--tag=CC' ,请查看libtool问题解决方案

##安装完成后,mmseg使用的词典和配置文件,将自动安装到/usr/local/mmseg3/etc中

##中文分词测试,显示不正常,请检查当前环境下的locale和UTF-8中文字符显示设置

$  /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc src/t1.txt

    中文/x 分/x 词/x 测试/x 

    中国人/x 上海市/x 

Word Splite took: 1 ms.

##安装coreseek:

##执行configure,进行编译配置:

cd ..

cd csft-4.1/

$ 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


$ make && make install

 

如果编译出错,出现类似于:

make[2]: *** [sphinxexpr.o] Error 1
make[2]: Leaving directory `/home/mac/Downloads/coreseek-4.1-beta/csft-4.1/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/mac/Downloads/coreseek-4.1-beta/csft-4.1/src'
make: *** [all-recursive] Error 1
的问题,需要打一个补丁:


一个有用的链接:http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=667378,是关于coreseek上游的sphinx的同样问题的,看了一下了解似乎是gcc 4.7的C++作用域的问题,上面的debian bugs里面提供了一个patch,看了下patch的内容,也对自己本地的coreseek的制作了同样的补丁,压缩包发布如下,使用时注意版本:sphinxexpr.cpp.patch.zip


root@china:/home/china/Downloads/coreseek-4.1-beta/csft-4.1# patch -p1 < /home/china/Downloads/sphinxexpr.cpp-csft-4.1-beta.patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- /home/china/Downloads/coreseek-4.1-beta/csft-4.1/src/sphinxexpr.cpp    2011-10-07 20:08:58.000000000 +0800
|+++ sphinxexpr.cpp    2012-04-16 13:47:35.237820912 +0800 QQ:327168521
--------------------------
File to patch:

在file to patch:后输入sphinxexpr.cpp文件的位置  我当时输入的是  /home/china/Downloads/coreseek-4.1-beta/csft-4.1/src/sphinxexpr.cpp

补丁打后就可以直接编译通过了



##配置测试,测试是否可以正确运行

$ /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx-min.conf.dist

##以下为正常测试时的提示信息:

   

Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 ERROR: nothing to do.

##至此,coreseek基础环境正常安装



$ cd testpack

 

$  /usr/local/coreseek/bin/indexer -c etc/csft.conf --all

 

$ /usr/local/coreseek/bin/search -c etc/csft.conf -a 服务

##以下为正常测试搜索关键词"服务"的数据

Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]

Copyright (c) 2007-2011,

Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 

 using config file 'etc/csft.conf'...

index 'xml': query '服务 ': returned 1 matches of 1 total in 0.015 sec

 

displaying matches:

1. document=3, weight=1, published=Wed Mar 31 21:01:00 2010, author_id=2

 

words:

1. '服务': 1 documents, 1 hits

 

$  /usr/local/coreseek/bin/searchd -c etc/csft.conf

##以下为正常开启搜索服务时的提示信息:(csft-4.0版类似)

   Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]

    Copyright (c) 2007-2010,

    Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 

    using config file 'etc/csft.conf'...

    listening on all interfaces, port=9312

##如要停止搜索服务,/usr/local/coreseek/bin/searchd -c etc/csft.conf --stop

##如要已启动服务,要更新索引,/usr/local/coreseek/bin/indexer -c etc/csft.conf --all --rotate

 

##然后,请参考csft-4.1下api目录中的相关文件,使用PHP、Python、Ruby、Java来测试搜索服务;也可以前往< a href="/products-install/step_by_step/">搜索服务建立三步曲,查看第三步使用PHP测试。


文章参考了并自己测试通过:http://blog.csdn.net/liangpz521/article/details/8795286和http://blog.csdn.net/andybegin/article/details/8724506

感谢原作者 本文转自 http://blog.csdn.net/whzhcahzxh/article/details/17533143

下面本人在 testpack下 测试mysql 测试不出来;于是在cd /usr/local/coreseek/etc/ 目录下

vim sphinx.conf 自己建立一个配置文件 代码如下

 source src1
{
        type                                    = mysql
        sql_host                                = localhost
        sql_user                                = root
        sql_pass                                = 111111
        sql_db                          = test
        sql_port                                = 3306  # optional, default is 3306
        sql_sock                              = /var/run/mysqld/mysqld.sock //这里一般是/tmp/mysql.sock或者/usr/lib/mysql/mysql.sock 等; 我这边找不到mysql.sock于是在my.cnf  发现是/var/run/mysqld/mysqld.sock 于是就写上了这个路径 然后就成功了
        sql_query_pre           = SET NAMES utf8
        sql_query                               =
                SELECT id,title,content FROM documents /*id必须有*/
        sql_query_info                  = SELECT * FROM documents WHERE id=$id
}

# 定义建立索引项
index test1
{
        source                                  = src1
        path                                    = /usr/local/coreseek/var/data/test1
    charset_type                        = zh_cn.utf-8
        charset_dictpath                = /usr/local/mmseg3/etc/
}

# 建索引程序的设置
indexer
{
    # 建索引时所用的内存限制
        mem_limit                               = 32M
}

# 提供服务的进程配置
searchd
{
        port                                    = 9312
        log                                             = /usr/local/coreseek/var/log/searchd.log
        query_log                               = /usr/local/coreseek/var/log/query.log
        read_timeout                    = 5
        max_children                    = 30
        pid_file                                = /usr/local/coreseek/var/log/searchd.pid
        max_matches                             = 1000
        seamless_rotate                 = 1
        preopen_indexes                 = 0
        unlink_old                              = 1
}

这里 在说一下 mysql导入命令 进入MySQL命令行模式 mysql>  然后执行source /usr/local/coreseek/etc/example.sql;

测试mysql命令

索引 /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf --all

上面如果报错 就执行 /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf  --rotate --all

Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 using config file '/usr/local/coreseek/etc/sphinx.conf'...
indexing index 'test1'...
WARNING: Attribute count is 0: switching to none docinfo //这里有个警告 可以不管它
collected 6 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 6 docs, 271 bytes
total 0.179 sec, 1507 bytes/sec, 33.36 docs/sec
total 2 reads, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg
total 6 writes, 0.000 sec, 0.1 kb/call avg, 0.1 msec/call avg

搜索测试 /usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/sphinx.conf 研究生
/usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/sphinx.conf  -a 研究生  //似乎加上-a和不加-a 结果一样 具体-a的含义 我也没搞明白

Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]
Copyright (c) 2007-2011,
Beijing Choice Software Technologies Inc (http://www.coreseek.com)

 using config file '/usr/local/coreseek/etc/sphinx.conf'...
index 'test1': query '研究生 ': returned 1 matches of 1 total in 0.001 sec

displaying matches:
1. document=5, weight=2787
        id=5
        group_id=2
        group_id2=3
        date_added=2011-02-01 00:37:12
        title=??????
        content=???????

words:
1. '研究生': 1 documents, 2 hits
到此 算是成功了

 /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/sphinx.conf  用php调用的命令

<?php
// --------------------------------------------------------------------------
// File name   : test_coreseek.php
// Description : coreseek中文全文检索系统测试程序
// Requirement : PHP5 (http://www.php.net)
//
// Copyright(C), HonestQiao, 2011, All Rights Reserved.
//
// Author: HonestQiao (honestqiao@gmail.com)
//
// 最新使用文档,请查看:http://www.coreseek.cn/products/products-install/
//
// --------------------------------------------------------------------------
<?php
require ( "sphinxapi.php" );

$cl = new SphinxClient ();
$cl->SetServer ( '127.0.0.1', 9312);
$cl->SetConnectTimeout ( 3 );
$cl->SetArrayResult ( true );
$cl->SetMatchMode ( SPH_MATCH_ANY);
$res = $cl->Query ( '研究生创业', "*" );
print_r($cl);
print_r($res);

?>