WEB开发网
开发学院服务器WEB服务器综合平台 Sphinx全文索引搜索常见的错误处理 阅读

Sphinx全文索引搜索常见的错误处理

 2013-04-11 14:46:02 来源:开发学院   
核心提示: sphinx无法启动的解决索引或者查询时提示:ERROR: invalid token in 配置文件 line 1 col 1.:该提示表示当前的配置文件的编码不是UTF-8(无BOM头)格式,无法正确解析,Sphinx全文索引搜索常见的错误处理,请使用编辑软件打开配置文件,另存为UTF-8(无BOM头)格式;错误

 sphinx无法启动的解决

索引或者查询时提示:ERROR: invalid token in 配置文件 line 1 col 1.:

该提示表示当前的配置文件的编码不是UTF-8(无BOM头)格式,无法正确解析,请使用编辑软件打开配置文件,另存为UTF-8(无BOM头)格式;

错误的编码格式包括:Unicode、Unicode BOM、Unicode big endian、Unicode 低位在前、UTF-8 + BOM、UTF-8 Signature、UTF-8 包含签名等;

特别注意:Windows自带的记事本(Notepad)或者写字板(WordPad)无法正确保存为所需格式,请勿使用其编辑配置文件;
 
在sphinx中处理使用特殊字符时所引起错误的办法
用sphinx搜索引擎时,有时会遇到一些特殊字符,这些特殊字符可能会是sphinx致命性错误来源:

如 “$”、“^”,在sphinx搜索关键字的最前或最尾出现这样的字符时(单独使用也一样),就会导致sphinx致命的错误。例如用“$笔记本”或“笔记本^”作为关键字搜索时,就会引起类似'Query failed: index product: syntax error, unexpected '"'。

    在搜索关键字的前面和后面自动加上半角的空格符“ ”可以解决此问题,且不会影响搜索结果。
 
ERROR: index ‘product’: raw_hits: write error: 122070 of 262017 bytes written
A:此类问题是索引写入磁盘错误导致,有多个原因。注意查看磁盘空间是否已满。另外,还可能是因为是否有多个indexer进程在进行,写入索引失败!还有个解决方法是:减少 indexer配置中 max_iosize的大小。max_iosize是sphinx最大允许的I/O操作大小,以字节为单位,用于I/O节流。比如可以设置为 524288(512KB)


1、增量索引,注意删除的问题 2、对大数据,一定要给sphinx数据目录留出大量空间,因为临时文件会占据非常大的空间
 
Q、编译安装时出现这个问题….sphinx.cpp; then mv -f “.deps/sphinx.Tpo” “.deps/sphinx.Po”; else rm -f “.deps/sphinx.Tpo”; exit 1; fi In file included from sphinx.cpp:14:sphinx.h:54:19: error: mysql.h: No such file or directory….
A:缺少libmysqlclient15.so,安装mysql-devel.如果已经存在。请使用ldconfig加载一下这个动态链接库(linux)
 
Q: sphinx在rotate时出现以下问题。(searchd.log) WARNING: rotating index ‘sphinx’: prealloc: mmap() failed: Cannot allocate memory (length=431854320); using old index,同时,在索引数据目录中会出现sphinx.spl sphinx.new.spl的情况,导致原来的索引不能正确的检索到
sphinx indexer有2个进程同时在运行,sphinx 的indexer不能同时使用,导致无法分配内存。并使indexer使用旧的索引文件
先了解一下sphinx的 –rotate机制:
indexer完成索引->发送SIGHUP 给searchd(同时在终端输出索引已经完成)->searchd接到中断信号->等待所有子进程退出->重命名 当前索引为旧索引为 .old
->重命名 .new 索引文件作为当前索引->尝试加载当前索引文件->如果加载失败,searchd会把.old文件回滚为当前文件,并把刚建立的新索引重命名 为 .new                             ->加载成的话:完成无缝衔接
执行 rotate开关情况下,indexer在完成索引后会首先会发送一个中断信号给searchd(并且会输出已经索引完成)。

接着 searchd会做以下事情:
1)等待所有子进程退出
2)重命名 当前索引为旧索引为 .old
3)重命名 .new 索引文件作为当前索引
4)尝试加载当前索引文件
5)如果加载失败,searchd会把.old文件回滚为当前文件,并把刚建立的新索引重命名为 .new
鉴于以上情况,很可能是开启了2个检测目录访问权限的进程。用户同时使用2个indexer且 searchd运行其下 等等
sphinx的searchd在启动时会创建一个 .spl 锁文件,并在关闭时会删除它。在indexer创建索引时如果发现有 .spl文件,则不会创建新索引,除非使用 –rotate
所以,出现这样的问题可能是 锁文件不知咋的就丢失啦,或者重建索引时没有使用 –rotate开关

原文:
http://www.sphinxsearch.com/forum/view.html?id=274
It seems that
a) the lock files were lost somehow, and
b) you ran indexer without –rotate switch.
Normally, searchd would create .spl lock files on startup (and kill them on shutdown),
and indexer would then refuse to reindex without –rotate switch.
indexers sends SIGHUP to searchd when completed (and it should print that out). searchd
then does the following:
1) waits for all children to exit
2) renames current index files to .old
3) renames .new index files to current
4) tries to load current index files
5) if something failed, it rollbacks current files from .old and new to .new
In your case I would start with double checking directory access rights, users which both
indexer and searchd run under, etc.
具体操作:
killall searchd 然后重启。重启后会自动加载重命名 sphinx.new.sp*为 sphinx.sp*
另外,出现这样的问题时,最好注意 –rotate的使用,在应用许可 的情况下,不妨直接采用 关闭searchd 再索引,然后再开启 searchd
Q:关于updateAttribute更新索引的问题
sphinx使用api不能马上真正的更新索引,但更新后api能显示索引已经是更新了。不过使用cli端的search就不能搜索到。只有在searchd重启后才会写入磁盘文件中。切记!
Q、sphinx安装make时,碰到libiconv的问题。
查了半天,改Makefile,configure都不可靠。最后在官站上查到:
./configure –without-iconv,就好了。NND,那干嘛还要这个iconv嘛。
看出错代码里,是在xmlunknowencode时才用到。我们都用utf-8,很多时候可能压根用不着这个功能!如若需要的话,可以加上这个lib
 
Q、检索出来后结果id排序问题
SELECT * FROM documents WHERE id IN (3,5,7) ORDER BY FIELD(id,3,5,7);

SELECT * FROM documents WHERE id IN (3,5,7) ORDER BY substring_index((id,3,5,7),id,1)
 
Q、WARNING: sort_hits: merge_block_size=248 kb too low, increasing mem_limit may improve performance
A、增大mem_limit的值
Q:sphinx排序问题
$sphinx->SetSortMode(SPH_SORT_EXTENDED,’status DESC,is_deleted DESC’); //组内排序 setGroupBy排序的话,分成组间排序和组内排序,比如:(317,1,hello),(317,0,world)。如果组内排序的话,需先使用SetSortMode(),进行自然排序,然后 使用group排序,这样在组间排序和组内排序都成自然状态了!
Q、WARNING: maxed out, dismissing client
这是sphinx 客户端找不到searchd守护进程。具体可能是索引的锁文件了 (***.spl)丢失,  这个文件通常是用来标识searchd是否开启。
通常客户端也会返回“zero-sized searchd response”。  解决办法:  重启searchd即可    作者的话:  It seems that a) the lock files were lost somehow, and b) you ran indexer without --rotate switch.  http://www.sphinxsearch.com/forum/view.html?id=247
Q、CentOS5.4 安装coreseek-3.2.13的mmseg 时,./configure 出现错误:config.status: error: cannot find input file: src/Makefile.in
 coreseek安装需要预装的软件:# yum install gcc gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel#aclocal#libtoolize --force#automake --add-missing#autoconf#autoheader重新configure即可!原文请参考:http://www.coreseek.cn/news/6/100/ 
Q:coreseek 在安装 make 时候出现 undefined reference to `libiconv’
A:编辑:
./src/MakeFile文件

LIBS = -lm -lexpat -L/usr/local/lib
改成
LIBS = -lm -lexpat -liconv -L/usr/local/lib
Q:在分布式搜索中api调用出现 search Error: unknown local index ‘allindex’ in search request
具体配置是index allindex
{
type                            = distributed
local                           =usertest1stemmed
local                           =testidx
agent                           = localhost:3306:agentdata1,agentdata2
agent_connect_timeout           = 1000
agent_query_timeout             = 3000
}
A:这里是sphinx在解析localhost的时候不能正确指向127.0.0.1 ,所以更改一下配置中的localhost即可。即:


agent                           = 127.0.0.1:3306:agentdata1,agentdata2

Tags:Sphinx 全文 索引

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接