- 浏览: 63694 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
zhaoaiqing:
bjb101
STRUTS + SPRING + IBATIS框架 -
soaryang:
...
STRUTS + SPRING + IBATIS框架 -
yh880709:
~~~~(>_<)~~~~
STRUTS + SPRING + IBATIS框架 -
yh880709:
密码我猜ssi
STRUTS + SPRING + IBATIS框架 -
tianlongsheji:
gyf6067 写道压缩文件解压需要密码,赵老大,密码是什么啊 ...
STRUTS + SPRING + IBATIS框架
首先我们要从 Sphinx 官网上 http://www.sphinxsearch.com/downloads.html 下载 mysql-5.0.45-sphinxse-0.9.8-win32.zip 和 sphinx-0.9.8.1-win32.zip,假设你已经安装好了 MySQL
先将 mysql 服务停掉 解压 mysql-5.0.45-sphinxse-0.9.8-win32.zip 将 bin 和 share 覆盖掉 mysql 目录中的 bin 和 share 解压 sphinx-0.9.8.1-win32.zip 到独立的目录,如:d:/www/sphinx/中
接着开启 mysql 服务,建立 "test" 数据库,并导入 sql 语句,如下:
-----------------------------------------------------------
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');
-------------------------------------------实际上,这个新建立的表就是 Sphinx 中的 example.sql
我们的测试表已经建立完成,接下来我们要配置 sphinx-doc.conf 文件(重要)
先将 sphinx 下的 sphinx-min.conf 复制一份改名为 sphinx-doc.conf,接着 修改它:
----------------------------------------------------------------------
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
# type----------------------------------------数据库类型,目前支持 mysql 与 pgsql
# strip_html--------------------------------是否去掉html 标签
# sql_host----------------------------------数据库主机地址
# sql_user----------------------------------数据库用户名
# sql_pass----------------------------------数据库密码
# sql_db-------------------------------------数据库名称
# sql_port-----------------------------------数据库采用的端口
# sql_query_pre--------------------------执行sql前要设置的字符集,用utf8必须SET NAMES utf8
# sql_query---------------------------------全文检索要显示的内容,在这里尽可能不使用where或 group by,将 where 与 groupby 的内容交给 sphinx,由 sphinx 进行条件过滤与 groupby 效率会更高
# 注意: select 出来的字段必须至少包括一个唯一主键 (ARTICLESID) 以及要全文检索的字段,你计划原本在 where 中要用到的字段也要 select 出来
# 这里不用使用orderby
# sql_attr_ 开头的表示一些属性字段,你原计划要用在 where, orderby, groupby 中的字段要在这里定义(# 为自己添加的注释内容)
#source 数据源名:
source documents
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = yourpassword
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
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_query_info = SELECT * FROM documents WHERE id=$id
}
index documents
{
source = documents
#path 索引记录存放目录,如 d:/sphinx/data/cgfinal ,实际存放时会存放在 d:/sphinx/data 目录,然后创建多个 cgfinal 名称,不同扩展名的索引文件。
path = d:/www/sphinx/data/doc
docinfo = extern
enable_star = 1
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
charset_type = sbcs
# 其他的配置如 min_word_len, charset_type, charset_table, ngrams_chars, ngram_len 这些则是支持中文检索需要设置的内容。
# 如果检索的不是中文,则 charset_table, ngrams_chars, min_word_len 就要设置不同的内容,具体官方网站的论坛中有很多,大家可以去搜索看看。
}
# mem_limit 索引使用内存最大限制,根据机器情况而定,默认是32M,太小的会影响索引的性能。
indexer
{
mem_limit = 32M
}
# 搜索的守护进程配置
# 在进行全文检索过程中,searchd要先开启,mysql在全文检索时才能连接到sphinx,由sphinx进行全文检索,再将结果返回给mysql
# address 侦听请求的地址,不设置则侦听所有地址
# port 侦听端口
searchd
{
port = 3312
log =d:/www/sphinx/logs/searched_doc.log
query_log = d:/www/sphinx/logs/query_doc.log
read_timeout = 5
max_children = 30
pid_file = d:/www/sphinx/logs/searched-doc.pid
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
}
----------------------------------------------------------------------
为了测试,我们的 Sphinx 配置文件已经写好,确保我们的 Mysql 数据库已经启动,如果没有启动则在 cmd 中键入" net start mysql "
接下来,我们的测试正式开始:
1,生成数据索引或重建索引:
(最好再复制一个 sphinx-doc.conf 配置文件,并把它放入 bin 文件夹中,下面的举例 假设我们已经这样做):
在 cmd 模式下:输入:
d:/www/sphinx/bin/indexer.exe --config d:/www/sphinx/bin/sphinx-doc.conf documents
2,运行检索守护进程 searchd.exe:
d:/www/sphinx/bin/searchd.exe --config d:/www/sphinx/bin/sphinx-doc.conf
如过这两步没有报错的话,说明我们的 Sphinx 已经正常运行了!可以通过 netstat -an 查看是否 3312 端口是否处如监听状态。
3,现在来用 sphinx 自带的工具 search.exe 来测试一下:
测试:
索引关键字: this is m
D:\www\sphinx\bin>search.exe -c d:/www/sphinx/bin/sphinx-doc.conf this is m
结果:
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff
using config file 'd:/www/sphinx/bin/sphinx-doc.conf'...
WARNING: index 'documents': invalid morphology option 'extern' - IGNORED
index 'documents': query 'this is m ': returned 4 matches of 4 total in 0.000 s
c
displaying matches:
1. document=1, weight=1, group_id=1, date_added=Sat Sep 13 21:37:47 2008
id=1
group_id=1
group_id2=5
date_added=2008-09-13 21:37:47
title=test one
content=this is my test document number one. also checking search withi
phrases.
2. document=2, weight=1, group_id=1, date_added=Sat Sep 13 21:37:47 2008
id=2
group_id=1
group_id2=6
date_added=2008-09-13 21:37:47
title=test two
content=this is my test document number two
3. document=3, weight=1, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=3
group_id=2
group_id2=7
date_added=2008-09-13 21:37:47
title=another doc
content=this is another group
4. document=4, weight=1, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=4
group_id=2
group_id2=8
date_added=2008-09-13 21:37:47
title=doc number four
content=this is to test groups
words:
1. 'this': 4 documents, 4 hits
-------------------
索引关键字: this is another group
D:\www\sphinx\bin>search.exe -c d:/www/sphinx/bin/sphinx-doc.conf this is another group
结果:
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff
-------------------
到此sphinx在win上算正常运行了,sphinx-doc.conf文件配置比较灵活,根据你需要索引的数据库进行灵活配置来达到你需要的效果
如果配置过程中出现运行参数配置问题可以查看 doc/sphinx.html文件,里面对各种参数都要详细的说明
using config file 'd:/www/sphinx/bin/sphinx-doc.conf'...
WARNING: index 'documents': invalid morphology option 'extern' - IGNORED
index 'documents': query 'this is another group ': returned 1 matches of 1 total
in 0.000 sec
displaying matches:
1. document=3, weight=4, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=3
group_id=2
group_id2=7
date_added=2008-09-13 21:37:47
title=another doc
content=this is another group
words:
1. 'this': 4 documents, 4 hits
2. 'another': 1 documents, 2 hits
3. 'group': 1 documents, 1 hits
先将 mysql 服务停掉 解压 mysql-5.0.45-sphinxse-0.9.8-win32.zip 将 bin 和 share 覆盖掉 mysql 目录中的 bin 和 share 解压 sphinx-0.9.8.1-win32.zip 到独立的目录,如:d:/www/sphinx/中
接着开启 mysql 服务,建立 "test" 数据库,并导入 sql 语句,如下:
-----------------------------------------------------------
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');
-------------------------------------------实际上,这个新建立的表就是 Sphinx 中的 example.sql
我们的测试表已经建立完成,接下来我们要配置 sphinx-doc.conf 文件(重要)
先将 sphinx 下的 sphinx-min.conf 复制一份改名为 sphinx-doc.conf,接着 修改它:
----------------------------------------------------------------------
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
# type----------------------------------------数据库类型,目前支持 mysql 与 pgsql
# strip_html--------------------------------是否去掉html 标签
# sql_host----------------------------------数据库主机地址
# sql_user----------------------------------数据库用户名
# sql_pass----------------------------------数据库密码
# sql_db-------------------------------------数据库名称
# sql_port-----------------------------------数据库采用的端口
# sql_query_pre--------------------------执行sql前要设置的字符集,用utf8必须SET NAMES utf8
# sql_query---------------------------------全文检索要显示的内容,在这里尽可能不使用where或 group by,将 where 与 groupby 的内容交给 sphinx,由 sphinx 进行条件过滤与 groupby 效率会更高
# 注意: select 出来的字段必须至少包括一个唯一主键 (ARTICLESID) 以及要全文检索的字段,你计划原本在 where 中要用到的字段也要 select 出来
# 这里不用使用orderby
# sql_attr_ 开头的表示一些属性字段,你原计划要用在 where, orderby, groupby 中的字段要在这里定义(# 为自己添加的注释内容)
#source 数据源名:
source documents
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = yourpassword
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
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_query_info = SELECT * FROM documents WHERE id=$id
}
index documents
{
source = documents
#path 索引记录存放目录,如 d:/sphinx/data/cgfinal ,实际存放时会存放在 d:/sphinx/data 目录,然后创建多个 cgfinal 名称,不同扩展名的索引文件。
path = d:/www/sphinx/data/doc
docinfo = extern
enable_star = 1
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
charset_type = sbcs
# 其他的配置如 min_word_len, charset_type, charset_table, ngrams_chars, ngram_len 这些则是支持中文检索需要设置的内容。
# 如果检索的不是中文,则 charset_table, ngrams_chars, min_word_len 就要设置不同的内容,具体官方网站的论坛中有很多,大家可以去搜索看看。
}
# mem_limit 索引使用内存最大限制,根据机器情况而定,默认是32M,太小的会影响索引的性能。
indexer
{
mem_limit = 32M
}
# 搜索的守护进程配置
# 在进行全文检索过程中,searchd要先开启,mysql在全文检索时才能连接到sphinx,由sphinx进行全文检索,再将结果返回给mysql
# address 侦听请求的地址,不设置则侦听所有地址
# port 侦听端口
searchd
{
port = 3312
log =d:/www/sphinx/logs/searched_doc.log
query_log = d:/www/sphinx/logs/query_doc.log
read_timeout = 5
max_children = 30
pid_file = d:/www/sphinx/logs/searched-doc.pid
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
}
----------------------------------------------------------------------
为了测试,我们的 Sphinx 配置文件已经写好,确保我们的 Mysql 数据库已经启动,如果没有启动则在 cmd 中键入" net start mysql "
接下来,我们的测试正式开始:
1,生成数据索引或重建索引:
(最好再复制一个 sphinx-doc.conf 配置文件,并把它放入 bin 文件夹中,下面的举例 假设我们已经这样做):
在 cmd 模式下:输入:
d:/www/sphinx/bin/indexer.exe --config d:/www/sphinx/bin/sphinx-doc.conf documents
2,运行检索守护进程 searchd.exe:
d:/www/sphinx/bin/searchd.exe --config d:/www/sphinx/bin/sphinx-doc.conf
如过这两步没有报错的话,说明我们的 Sphinx 已经正常运行了!可以通过 netstat -an 查看是否 3312 端口是否处如监听状态。
3,现在来用 sphinx 自带的工具 search.exe 来测试一下:
测试:
索引关键字: this is m
D:\www\sphinx\bin>search.exe -c d:/www/sphinx/bin/sphinx-doc.conf this is m
结果:
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff
using config file 'd:/www/sphinx/bin/sphinx-doc.conf'...
WARNING: index 'documents': invalid morphology option 'extern' - IGNORED
index 'documents': query 'this is m ': returned 4 matches of 4 total in 0.000 s
c
displaying matches:
1. document=1, weight=1, group_id=1, date_added=Sat Sep 13 21:37:47 2008
id=1
group_id=1
group_id2=5
date_added=2008-09-13 21:37:47
title=test one
content=this is my test document number one. also checking search withi
phrases.
2. document=2, weight=1, group_id=1, date_added=Sat Sep 13 21:37:47 2008
id=2
group_id=1
group_id2=6
date_added=2008-09-13 21:37:47
title=test two
content=this is my test document number two
3. document=3, weight=1, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=3
group_id=2
group_id2=7
date_added=2008-09-13 21:37:47
title=another doc
content=this is another group
4. document=4, weight=1, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=4
group_id=2
group_id2=8
date_added=2008-09-13 21:37:47
title=doc number four
content=this is to test groups
words:
1. 'this': 4 documents, 4 hits
-------------------
索引关键字: this is another group
D:\www\sphinx\bin>search.exe -c d:/www/sphinx/bin/sphinx-doc.conf this is another group
结果:
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff
-------------------
到此sphinx在win上算正常运行了,sphinx-doc.conf文件配置比较灵活,根据你需要索引的数据库进行灵活配置来达到你需要的效果
如果配置过程中出现运行参数配置问题可以查看 doc/sphinx.html文件,里面对各种参数都要详细的说明
using config file 'd:/www/sphinx/bin/sphinx-doc.conf'...
WARNING: index 'documents': invalid morphology option 'extern' - IGNORED
index 'documents': query 'this is another group ': returned 1 matches of 1 total
in 0.000 sec
displaying matches:
1. document=3, weight=4, group_id=2, date_added=Sat Sep 13 21:37:47 2008
id=3
group_id=2
group_id2=7
date_added=2008-09-13 21:37:47
title=another doc
content=this is another group
words:
1. 'this': 4 documents, 4 hits
2. 'another': 1 documents, 2 hits
3. 'group': 1 documents, 1 hits
- sphinx-0.9.8-win32.zip (1.8 MB)
- 下载次数: 97
- mysql-5.0.45-sphinxse-0.9.8-win32.zip (2.7 MB)
- 下载次数: 95
发表评论
-
版本说明
2016-02-27 18:03 415spring-core-4.0.2.RELEASE.jar 总 ... -
oracle 常用命令
2012-03-30 22:14 648oracle\product\10.2.0\db_1\NETW ... -
JBPM
2011-12-12 09:54 646JBPM4.chm -
关于 tuscany + sping + hibernate 整合时jar包冲突
2011-10-11 11:19 858tuscany 1.6 + spring 2.5.5 + hi ... -
线程同步2
2011-10-07 20:34 698如果某个synchronized 方法是static 的,那么 ... -
关于JAVA线程同步
2011-10-07 20:15 777如果一个对象有多个 synchronized ,某个时刻某个线 ... -
排序方法
2011-05-25 16:55 933package cn.org.test; public c ... -
Freemarker 手册中文翻译
2010-11-10 13:23 796Freemarker 手册中文 下载 -
Spring 属性注入(int ,String, List, Map, Set, String[])
2010-09-24 01:04 26001.JavaBean import java.uti ... -
TOMCAT 安全访问设定
2010-09-16 19:43 928TOMCAT 安全访问设定 WEB.xml <se ... -
XPath表达式
2010-07-16 16:04 839XPath(eXtensible Path)可扩展路径:主要用 ... -
XML
2010-07-16 16:04 749XML是可扩展的标记语言(eXtensible Markup ... -
旅游游
2010-04-19 20:42 0魂牵梦萦魂牵梦萦 http://blog.sina.com.c ... -
STRUTS + SPRING + IBATIS框架
2010-03-30 13:17 2014STRUTS + SPRING + IBATIS框架 web ... -
世博园 旅游社区
2010-03-29 14:04 817http://www.you1you.net/yy/after ... -
nginx
2010-03-16 23:40 0http://gzip.zzbaike.com/ http:/ ...
相关推荐
经过生产环境检验的千万级数据全文检索(搜索引擎)架构 Sphinx+MySQL
基于Sphinx+MySQL的千万级数据全文检索(搜索引擎)架构设计
基于Sphinx+MySql+Python的站内搜索引擎的设计与实现.pdf
搭建Sphinx+MySQL5.1x+SphinxSE+mmseg中文分词搜索引擎架构
基于Sphinx+MySql+Python的站内搜索引擎的设计与实现
基于Sphinx+MySQL的千万级数据全文检索(搜索引擎) 架构设计,本文阐述的是一款经过生产环境检验的千万级数据全文检索(搜索引擎)架构
PHP+Mysql+Sphinx高效的站内搜索引擎搭建详释.docx
出自俄罗斯的开源全文搜索引擎软件Sphinx,单一索引 最大可包含1亿条记录,在1千万条记录情况下的查询速度为0.x秒(毫秒级)。Sphinx创建索引的速度为:创建100万条记录的索引只需3~4分钟, 创建1000万条记录的索引...
php+mysql+sphinx实现近实时索引,不过按照配置不成功,请留言。
主要介绍了PHP+MySQL+sphinx+scws实现全文检索功能,详细分析了sphinx、scws的下载安装、配置、数据库创建及全文检索功能的相关实现技巧,需要的朋友可以参考下
sphinx+php检索引擎
二、MYSQL+SPHINX+SPHINXSE安装步骤: 5 1、安装python支持 5 2、编译安装LibMMSeg 5 3、编译安装MySQL 5.1.26-rc、Sphinx、SphinxSE存储引擎 5 4、创建Sphinx索引文件和MySQL数据文件存放目录 6 5、创建MySQL配置...
使用PHP+Sphinx建立高效的站内搜索引擎
sphinx+xdict资源包
sphinx+php+mysqli检索测试
Sphinx+Python+Oracle构建全文检索系统.pdf
数据库 搜索引擎,通过web实现,对数据库的搜索
主要介绍了centos+php+coreseek+sphinx+mysql之一coreseek安装篇的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下