安哥网络 发表于 2013-12-29 19:16:34

sphinx整合到mysql(master/slave)中-it论坛-计算机论坛

sphinx整合到mysql(master/slave)中-it论坛-计算机论坛
sphinx版本使用的是coreseek修改的支 持中文检索的版本,中文词库使用 coreseek开发的libmmseg
mysql受sphinx中sphinxse引擎要求安装了mysql-5.0.37做生产环境的mysql-5.0.70的从库
编译sphinx,libmmseg以及mysql:
编译安装libmmseg:

view plaincopy


[*]./configure --prefix=/usr/local/mmseg && make -j5 && make install


copy 解压缩后的sphinx目录中的mysqlse中的文件到mysql下的sql/sphinx/中 it论坛-计算机论坛

给mysql打sphinx的补丁

view plaincopy


[*]patch -p1 < sql/sphinx/sphinx.5.0.37.diff


编译mysql:
view plaincopy


[*]./configure --prefix=/data/app/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-readlin
[*]e --with-big-tables --enable-local-infile --with-sphinx-storage-engine --without-innobase
[*]make -j5 && make install


编译sphinx
view plaincopy


[*]CPPFLAGS=-I/usr/include/python2.5 LDFLAGS=-lpython2.5 ./configure --prefix=/data/app/sphinx --with-mysql=/data/app/mysql --with-mmse
[*]g=/data/app/mmseg --with-mmseg-includes=/data/app/mmseg/include/mmseg --with-mmseg-libs=/data/app/mmseg/lib
[*]make -j5 && make install


配置mysql主从

.
view plaincopy


[*]master -> slave


生成字典文件:
view plaincopy


[*]mmseg -u unigram.txt
[*]mv unigram.txt.lib /data/app/dict/uni.lib


配置sphinx.conf

view plaincopy


[*]source source_name {...} #做全文检索的内容源
[*]source source_name_increase:source_name {...} #做增量检索的源
[*]index index_name {...} #做索引的配置
[*]index index_name_increase:index_name {...} #做增量索引的配置
[*]indexer {...} #indexer进程的设置
[*]searched {...} #searched进程的设置


建立在增量索引需要使用的数据表以及SPHINX引擎需要的表: it论坛-计算机论坛


view plaincopy


[*]CREATE TABLE `sphcounter` (
[*]`counterid` int(11) NOT NULL,
[*]`max_doc_id` int(11) NOT NULL,
[*]PRIMARY KEY(`counterid`)
[*]) ENGINE=MyISAM
[*]
[*]CREATE TABLE `sphinx` (
[*]`id` int(11) NOT NULL,
[*]`weight` int(11) NOT NULL,
[*]`query` varchar(255) NOT NULL,
[*]KEY `Query` (`query`)
[*]) ENGINE=SPHINX DEFAULT CHARSET=utf8 CONNECTION='sphinx://localhost:3312/cbid_index';


建立启动脚本以及建立索引的脚本:

view plaincopy


[*]#!/bin/bash
[*]/data/app/sphinx/bin/indexer --all --config /data/app/sphinx/etc/sphinx.conf



sphinx.increase
view plaincopy


[*]#!/bin/bash
[*]/data/app/sphinx/bin/searchd --stop
[*]/data/app/sphinx/bin/indexer cbid_index_stremmed --config /data/app/sphinx/etc/sphinx.conf
[*]/data/app/sphinx/bin/indexer --merge cbid_index cbid_index_stremmed --config /data/app/sphinx/etc/sphinx.conf
[*]/data/app/sphinx/bin/searchd


启动所有的服务,然后测试:



view plaincopy


[*]<?php
[*]$keyword = $_POST['keyword'];
[*]if($_POST['keyword'] != '')
[*]{
[*]$link = mysql_connect('localhost:/tmp/mysql.sock', 'root', 'xxxxxxxx') or die ("can't connect database");
[*]$db_select = mysql_select_db('dba', $link);
[*]$result = mysql_query("SELECT * FROM `dba`.`article` JOIN `sphinx`.`sphinx` ON ( dba.article.art_id = sphinx.sphin
[*]x.id ) WHERE query = '$keyword; limit=10000' AND dba.article.is_show = '1' ORDER BY id DESC ") or die ("sphinx Maintenance ing ...");
[*]while($rows = mysql_fetch_array($result))
[*]{
[*]$pub_date = date('Y-m-d', $rows["pub_date"]);
[*]printf("<a href="article.php?aid=%s" mce_href="article.php?aid=%s">%s</a> %s <br />", $rows["art_id"],$rows["art_name"],$pub_date);
[*]}
[*]mysql_free_result($result);
[*]mysql_close($link);
[*]}
[*]?>
[*]<html>
[*]<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
[*]<body>
[*]<form name="search" method="post" action="newsearch.php">
[*]<input type="text" name="keyword">
[*]<input type="submit" vilue="search">
[*]</body>
[*]</html>


本文摘自:http://blog.csdn.net/lgm252008/article/details/5375629

页: [1]
查看完整版本: sphinx整合到mysql(master/slave)中-it论坛-计算机论坛