sphinx使用整理文件

2021-07-14 04:09:51 字數 2959 閱讀 2081

相關命令及步驟

建立主索引:

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

檢視狀態

ps -ef | grep searchd

建立增量索引:

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_mysql.conf delta

重啟索引程序

/usr/local/coreseek/bin/searchd --stop

/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf

索引合併

/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --merge main delta --rotate

csft_mysql.conf配置檔案

source src1

index test1

source delta : src1

index delta : 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)

// 獲取結果id集

$ids = array();

foreach($result['matches'] as $key => $val)

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" => "",

"after_match" => ""

);foreach ($data as $key=>$val)

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多種資料來源id重複問題處理思路 1.1修改文件id,將源id編碼進去 source src1 source src2 1.2 source src1 source src2 2 sql field string 與 sql attr string 區別 字串 很明顯!但前者僅用於檢索,而後者可作...

使用Sphinx編寫文件

作業系統 windows7 x64 python 版本 2.7.10 sphinx 版本 使用pip安裝 pip install u sphinx pip install sphinx rtd theme 從原始碼安裝 在控制台輸入以下命令 sphinx quickstart 根據實際情況填寫。in...

sphinx配置文件

sphinx的配置 source 源名稱1 index 索引名稱1 source 源名稱2 index 索引名稱2 indexer searchd type 資料庫型別 mysql 或sql sql user 資料庫使用者名稱 sql pass 資料庫密碼 sql db 資料庫名稱 sql port...