- 浏览: 66299 次
- 性别:
- 来自: 上海
-
文章分类
最新评论
-
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 453spring-core-4.0.2.RELEASE.jar 总 ... -
oracle 常用命令
2012-03-30 22:14 685oracle\product\10.2.0\db_1\NETW ... -
JBPM
2011-12-12 09:54 682JBPM4.chm -
关于 tuscany + sping + hibernate 整合时jar包冲突
2011-10-11 11:19 894tuscany 1.6 + spring 2.5.5 + hi ... -
线程同步2
2011-10-07 20:34 739如果某个synchronized 方法是static 的,那么 ... -
关于JAVA线程同步
2011-10-07 20:15 839如果一个对象有多个 synchronized ,某个时刻某个线 ... -
排序方法
2011-05-25 16:55 965package cn.org.test; public c ... -
Freemarker 手册中文翻译
2010-11-10 13:23 854Freemarker 手册中文 下载 -
Spring 属性注入(int ,String, List, Map, Set, String[])
2010-09-24 01:04 26551.JavaBean import java.uti ... -
TOMCAT 安全访问设定
2010-09-16 19:43 963TOMCAT 安全访问设定 WEB.xml <se ... -
XPath表达式
2010-07-16 16:04 882XPath(eXtensible Path)可扩展路径:主要用 ... -
XML
2010-07-16 16:04 795XML是可扩展的标记语言(eXtensible Markup ... -
旅游游
2010-04-19 20:42 0魂牵梦萦魂牵梦萦 http://blog.sina.com.c ... -
STRUTS + SPRING + IBATIS框架
2010-03-30 13:17 2068STRUTS + SPRING + IBATIS框架 web ... -
世博园 旅游社区
2010-03-29 14:04 854http://www.you1you.net/yy/after ... -
nginx
2010-03-16 23:40 0http://gzip.zzbaike.com/ http:/ ...
相关推荐
Sphinx是一款高性能的全文搜索引擎,常用于构建高效的数据检索系统。结合MySQL数据库,可以构建出强大的、适用于千万级数据的全文检索解决方案。本手册将详细讲解如何在生产环境中安装和配置Sphinx以及与MySQL的集成...
数据库搜索引擎Sphinx是一款高效、可定制且功能丰富的全文搜索引擎,主要设计用于Web应用,以便快速地从大量数据中检索相关信息。Sphinx的核心特性包括实时索引、近实时搜索以及高度可扩展性,使得它在处理大数据量...
描述中的“JAVA有ElasticSearch搜索引擎,我们PHP也有”暗示了尽管Java有一个强大的全文搜索引擎Elasticsearch,PHP也有类似的功能强大的解决方案——Sphinx。这表明开发者可以在PHP环境中享受到类似于Java的全文搜索...
Sphinx 是一个高性能、全文检索引擎,常用于构建搜索引擎或者数据检索系统。它支持多种数据库,包括 MySQL,能够实现快速的全文搜索,并提供布尔运算、短语搜索、权重计算等功能。在“sphinx 测试可用 改下数据库”...
假设一个电子商务网站需要提供商品搜索功能,面对成千上万的商品信息,传统的数据库搜索可能无法满足速度和精度的需求。此时,引入Sphinx进行全文搜索成为一种理想的解决方案。通过与数据库同步建立商品信息的索引,...
Sphinx是一款开源的全文搜索引擎,特别适用于需要高效、精确全文搜索功能的应用程序。它由俄罗斯开发者Andrew Aksyonoff创建,最初是为了解决数据库的全文检索问题而设计的。Sphinx以其快速、准确和可扩展性而闻名,...
Sphinx搜索引擎是一款高效、强大的全文检索引擎,专为大规模数据处理和实时搜索而设计。它在处理海量数据时表现出色,对于需要快速、精准检索大数据的应用场景尤其有用。以下是对Sphinx搜索引擎及其相关知识点的详细...
Sphinx 是一个强大的开源全文搜索引擎,它以性能卓越、相关性高和易于集成著称。在深入了解Sphinx之前,我们先来理解全文搜索的基本概念。全文搜索允许用户输入自然语言查询,然后在文档集合中搜索匹配的内容,而不...
Sphinx是一个高效、开源的全文检索引擎,主要用于提供快速、低空间消耗以及高度相关的全文搜索服务。它支持多种编程语言,包括PHP、Python、Perl、Ruby和Java等,并且能够作为MySQL的一种存储引擎来使用。Sphinx支持...
Sphinx 是一个开源全文搜索引擎,它为各种编程语言(如Python、PHP、Java等)提供了API,使得开发者能够轻松地在自己的应用中集成强大的搜索功能。sphinx-0.9.8.tar.gz 是该软件的一个特定版本的源码包,打包格式为...
Sphinx是一款高性能的全文搜索引擎,主要用于提高大型数据集的搜索效率。它能够独立运行,也可以作为应用程序的一部分嵌入到其他软件中。Sphinx主要适用于对性能要求较高的场景,如实时搜索、大数据量搜索等。 ####...
Sphinx是一个在GPLv2许可下发布的全文检索引擎,具有高度优化的索引建立速度和快速的搜索响应时间。而Coreseek则是在Sphinx基础上针对中文进行了优化的全文检索引擎,它同样遵循GPLv2协议发行,但商业使用需要获得...
Sphinx 是一个强大的全文搜索引擎库,它被广泛用于构建高效、可扩展的搜索功能,尤其在Web应用中。"sphinx-0.9.9"是Sphinx的一个特定版本,适用于MySQL 5.0及更高版本。这个压缩包可能包含了Sphinx在0.9.9版本的所有...
Sphinx是一个开源全文搜索引擎,专为高速、高精度和低维护设计。它的主要特点是对大量文本数据进行快速、准确的全文检索。UTF全文搜索则强调了Sphinx支持多语言,特别是对Unicode字符集(包括UTF-8编码)的良好支持...
一般而言,Sphinx是一个独立的搜索引擎,意图为其他应用提供高速、低空间占用、高结果相关度的全文搜索功能。Sphinx可以非常容易的与SQL数据库和脚本语言集成。 当前系统内置MySQL和PostgreSQL 数据库数据源的支持...
Sphinx 是一个强大的全文搜索引擎库,它主要用于构建可搜索的文档和网站。Sphinx-3.0.2-linux-amd64 是一个针对64位Linux系统的特定版本,该版本的Sphinx软件包版本号为3.0.2,对应Git提交ID为2592786。在考虑使用这...
【Java开发资源】是一个专为Java开发者准备的实用工具集合,其中包括了数据库搜索优化工具——Sphinx。Sphinx是一款高效、可扩展的全文搜索引擎库,它不仅被广泛应用于Web应用程序,也被很多Java项目所采纳,以提升...
Sphinx作为一个强大的全文搜索引擎,被广泛应用于行业搜索、论坛搜索、数据库搜索、文档检索、信息检索以及数据挖掘等任务中。 Sphinx的核心特性包括以下几个方面: 1. **高效索引**:Sphinx支持实时索引,能够在...
#### 一、Sphinx 搜索引擎简介 Sphinx是一款高性能全文搜索引擎,被广泛应用于需要快速准确检索大量文本数据的应用场景中。它支持多种数据库(如MySQL、PostgreSQL等)和编程语言(如PHP、Python、Java等),能够...