相关命令及步骤
    创建主索引:
        /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all
    创建增量索引:
        1. 创建测试数据表以及数据
        2. 修改配置文件
            主索引源:sql_query_pre
            增量索引源:sql_query_pre  sql_query  sql_query_post
            主索引:source path
            增量索引:source path
        3. 创建/更新主索引
        4. 创建/更新增量索引
        /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf delta
    重启索引进程
        /usr/local/coreseek/bin/searchd --stop
        /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf
    索引合并
        /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --merge main delta --rotate

csft.conf配置文件
    source src1
    {
        type                    = mysql
        sql_host                = 127.0.0.1
        sql_user                = root
        sql_pass                =
        sql_db                  = test
        sql_port                = 3306  # optional, default is 3306

sql_query_pre           = SET NAMES utf8
        sql_query_pre           = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents

sql_query               = \
            SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
            FROM documents

sql_attr_uint           = group_id

sql_attr_timestamp      = date_added

sql_ranged_throttle = 0

sql_query_info      = SELECT * FROM documents WHERE id=$id

}

index test1
    {
        source          = src1

path            = /usr/local/coreseek/var/data/test1

docinfo         = extern

mlock           = 0

morphology      = none

stopwords           = /usr/local/coreseek/var/data/test1/stopwords.txt

wordforms           = /usr/local/coreseek/var/data/test1/wordforms.txt

min_word_len        = 1

charset_type        = sbcs

html_strip              = 0

}

source delta : src1
    {
        sql_query_pre = SET NAMES utf8
        sql_query = SELECT \
                        id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
                    FROM documents \
                    WHERE \
                        id>( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
        sql_query_post = UPDATE sph_counter SET max_doc_id=(SELECT MAX(id) FROM documents) where counter_id=1
    }

index delta : test1
    {
        source = delta
        path = /usr/local/coreseek/var/data/test1
    }

创建mysql测试数据表及数据
   
CREATE TABLE `documents` (`id` int(11) NOT NULL
auto_increment,`group_id` int(11) NOT NULL,`group_id2` int(11) NOT
NULL,`date_added` datetime NOT NULL,`title` varchar(255) NOT
NULL,`content` text NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB
AUTO_INCREMENT=5;

INSERT INTO `documents` VALUES ('1', '1',
'5', '2008-09-13 21:37:47', 'test one', 'this is my test document number
one. also checking search within phrases.');INSERT INTO `documents`
VALUES ('2', '1', '6', '2008-09-13 21:37:47', 'test two', 'this is my
test document number two');INSERT INTO `documents` VALUES ('3', '2',
'7', '2008-09-13 21:37:47', 'another doc', 'this is another
group');INSERT INTO `documents` VALUES ('4', '2', '8', '2008-09-13
21:37:47', 'doc number four', 'this is to test groups');

// 实现增量索引时使用的计数表
    CREATE TABLE sph_counter( counter_id INTEGER PRIMARY KEY NOT NULL, max_doc_id INTEGER NOT NULL);

PHP使用

<?php

header("Content-type: text/html; charset=utf-8");

require_once('sphinxapi.php');

$s = new SphinxClient();

$s->setServer("127.0.0.1", 9312);
    $s->setArrayResult(true);
    $s->setMatchMode(SPH_MATCH_ALL);

$keyword = 'test';

$result = $s->Query($keyword, '*');
    if ($result['total'] == 0) {
        echo '无搜索结果';die;
    }

// 获取结果id集
    $ids = array();
    foreach($result['matches'] as $key => $val)
    {
        $ids[] = $val['id'];
    }
    print_r($ids);

// 连接数据库
    $dsn = "mysql:host=localhost;dbname=test;charset=utf8";
    $db = new PDO($dsn, 'root', '');

$sql = 'select * from documents where id in('.implode(',', $ids).')';
    $result = $db->query($sql);
    $result->setFetchMode(PDO::FETCH_ASSOC);

$data = $result->fetchAll();

// 搜索结果高亮显示
    $rule = array(
                "before_match" => "<font style='font-weight:bold;color:#f00'>",
                "after_match" => "</font>"
            );
    foreach ($data as $key=>$val) {
        $data[$key] = $s->BuildExcerpts($val, 'delta', $keyword, $rule);
    }

print_r($data);

添加新分词
    1. 复制unigram.txt文件为unigram_new.txt
    2. 在unigram_new.txt中添加新词
    3. 生成新的词典文件:/usr/local/mmseg3/bin/mmseg -u /usr/local/mmseg3/etc/unigram_new.txt
    4. 替换原有的uni.lib文件
    5. 重建索引 && 重启索引

sphinx安装的更多相关文章

  1. Linux Sphinx 安装与使用

    一.什么是 Sphinx? Sphinx 是一个基于SQL的全文检索引擎,可以结合 MySQL,PostgreSQL 做全文搜索,它可以提供比数据库本身更专业的搜索功能,使得应用程序 更容易实现专业化 ...

  2. sphinx 安装使用

    一.linux(centos)下安装源码包 1.下载  wget http://sphinxsearch.com/files/sphinx-2.3.1-beta.tar.gz 2.安装   切换目录到 ...

  3. Sphinx安装配置应用

    Sphinx 是由俄罗斯人Andrew Aksyonoff开发的一个全文搜索引擎.意图为其他应用提供高速.地空间占用.高结果相关度的全文搜索功能.Sphinx可以非常容易的与SQL数据库和脚本语言集成 ...

  4. sphinx安装记录 转

    [转]sphinx服务器安装及配置详解 安装PHP sphinx扩展 1.架构:ip192.168.0.200 redhat5.4(64位)2.安装   #cd /usr/local/src   #y ...

  5. ubuntu下 mysql5.6.4 +sphinx安装

    安装mysql 5.6.4 下载源码 安装cmake sudo apt-get install cmake 进入mysql源码包: 创建mysql用户与用户组 groupadd mysql usera ...

  6. coreseek(sphinx)安装1(xml数据源配置和测试)

    1.下载coreseek-3.2.14-32版本.网址:http://www.coreseek.cn/products-install/install_on_windows/   (有详细的安装说明) ...

  7. CoreSeek Sphinx 安装

    1.centos Sphinx 先安装 yum install postgresql-libs yum install unixODBC CoreSeek 安装: http://www.coresee ...

  8. Sphinx安装流程及配合PHP使用经验

    1.什么是Sphinx Sphinx是俄罗斯人Andrew Aksyonoff开发的高性能全文搜索软件包,在GPL与商业协议双许可协议下发行. 全文检索式指以文档的全部文本信息作为检索对象的一种信息检 ...

  9. Sphinx 安装与使用

    Sphinx 优点 高速索引(接近10M/S) 高速搜索(2-4G文本搜索耗时不到0.1秒) 高可用性(单CPU支持100GB文本,100M文档) 提供相关性排名.分布式搜索.文档摘要(高亮显示) S ...

  10. Sphinx 安装与使用(1)-- 安装Coreseek

    Coreseek就是Sphinx的中文版 官方网站 http://www.coreseek.cn/ 一.安装 1.修改LANG 永久修改: vim /etc/locale.conf LANG=&quo ...

随机推荐

  1. ubuntu下chromium浏览器flash插件安装

    ubuntu下chromium浏览器默认是不支持flash的,在新立德软件包中搜索flash得到的“Adobe Flash Player plugin installer”也没有什么卵用,因为装完以后 ...

  2. Backtrack下的dns爆破工具的目录

    直接可以切换到 /pentest/enumeration/dns#

  3. 201521123032 《Java程序设计》第13周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 1. 网络基础 1.1 比较ping www.baidu.com与ping cec.jmu ...

  4. 视频转GIF图

    1.工具 PS6.0(其他版本也可以) 视频一个(具体格式应该无所谓) 2.步骤 (1)打开PS,点击导入->视频帧到图层 (2)选择视频打开 (3)进行范围选择.由于每隔2帧导入一张图片,每秒 ...

  5. mybatis-mapper文件介绍

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...

  6. python实现算24的算法

    1.介绍 给定4个整数,数字范围在1-13之间,任意使用 + - * / ( ) ,构造出一个表达式,使得最终结果为24,这就是常见的算24的游戏.本文介绍用Python语言实现的两种方式.2.实现思 ...

  7. [UIKit学习]02.关于UIButton

    按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置 按钮也是一种容器,在这一点上跟UIView类似 按钮的三种状态 normal(普通状态) 默认情况(Default) 对 ...

  8. Vuforia开发完全指南---License Manager和Target Manager详解

    License Manager和Target Manager License Manager 对于每一个用Vuforia开发的AR程序来说,都有一个唯一的license key,在Unity中必须首先 ...

  9. JAVA多线程--Thinking in java

    聊聊并发:http://ifeve.com/java-concurrency-thread-directory/ 阻塞状态: sleep  可中断利用 interrupt方法 wait IO  不可中 ...

  10. Writing Science 笔记 6.19

    1.练习由三个部分组成:写短文,反复修改:分析别人的文章是怎么写的:练习句子结构,如何用词. 2.写作的目的不在于发表而在于能够给人以灵感从而使文章得到更多的引用. 3.写得清楚,你必须清楚地思考,无 ...