我使用本教程将原始的sphinx索引转换为实时索引:http://www.ivinco.com/blog/converting-sphinx-original-indexes-to-real-time-indexes/
我改变了我的sphinx.conf:
source movies_dev
{
type = mysql
sql_host = localhost
sql_user = ********
sql_pass = ********
sql_db = ********
sql_sock = /var/run/mysqld/mysqld.sock
sql_port = 3306
sql_query = \
SELECT \
CRC32(movie_id) AS id, movie_id, format_id, active, year, title \
FROM \
movie;
sql_attr_uint = format_id
sql_attr_uint = active
sql_attr_uint = year
sql_field_string = movie_id
sql_field_string = title
sql_query_info = SELECT * FROM movie WHERE CRC32(movie_id)=$id
sql_query_pre = SET NAMES utf8
}
index movies_dev
{
source = movies_dev
path = /var/data/sphinx/movies_dev
morphology = stem_en
enable_star = 1
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
charset_type = utf-8
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F, U+DC->U+FC, U+C4->U+E4, U+D6->U+F6, U+DF, U+E4, U+F6, U+FC
}
index rt_movies_dev
{
type = rt
rt_mem_limit = 32M
path = /var/data/sphinx/rt_movies_dev
charset_type = utf-8
rt_field = movie_id
rt_field = title
rt_attr_uint = format_id
rt_attr_uint = year
rt_attr_uint = active
}
source attach_movies_dev
{
type = mysql
sql_host = localhost
sql_user = ********
sql_pass = ********
sql_db = ********
sql_query = SELECT 1 FROM rt_movies_dev
sql_query_post = ATTACH INDEX movies_dev TO RTINDEX rt_movies_dev
}
index attach_movies_dev
{
source = attach_movies_dev
path = /var/data/sphinx/attach_movies_dev
docinfo = extern
charset_type = utf-8
}
我创建了“rt_movies_dev”表:
SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = '+01:00';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `rt_movies_dev`;
CREATE TABLE `rt_movies_dev` (
`movie_id` varchar(20) NOT NULL,
`format_id` int(10) NOT NULL,
`title` varchar(255) NOT NULL,
`year` int(20) DEFAULT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`movie_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
之后,我运行这三个命令:
root@server:~# /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf;
root@server:~# /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf movies_dev --rotate;
root@server:~# /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf attach_movies_dev;
前两个命令后没有错误(除了教程中的警告之外)。 但最后一个命令抛出了这个:
ERROR: index 'attach_movies_dev': No fields in schema - will not index.
我不确切地知道错误是什么,我找不到任何有用的东西。你能说出错了吗?我被困在这里。
答案 0 :(得分:0)
首先是attach_movies_dev源码,连接到SPHINX,而不是mysql。所以不需要mysql表。
您只是使用索引器来调用SphinxQL命令。
但是从我所看到的尝试索引附加索引,将始终导致错误,因为RT索引本身必须为空(因此可以附加磁盘索引!)
因此,请更改附加索引以连接到searchd。它应该更好。可能是一个空的RT索引,没关系,索引器只会创建一个空索引,但重要的是它仍然会运行_post命令。这是索引存在的全部原因!
还要注意您的磁盘索引和RT索引具有不同的字段,在磁盘索引中,您有两个sql_field_string,它们同时创建属性AND字段。所以你的RT索引应该包含两个匹配的字符串属性(而不仅仅是字段)。