我是Sphinx的新手,请尝试在sphinx.conf中设置'index'。
当我运行命令“ indexer.exe --all --rotate --config C:\ sphinx \ etc \ sphinx.conf”时,我发现了这样的错误:
using config file 'c:\sphinx\etc\sphinx.conf'...
indexing index 'warehouse1'...
ERROR: index 'warehouse1': first column in SQL query result must be document ID; found 'code_attr' attribute instead.
total 0 docs, 0.0 Kb
total 0.0 sec, 0.0 Kb/sec, 0 docs/sec
这是我的sphinx.conf
source warehouse
{
type = mysql
sql_host = localhost
sql_user = sphinx
sql_pass = sphinx_password
sql_db = test
sql_port = 3306
sql_query_pre = SELECT @id := 0
sql_query = \
SELECT @id := @id + 1 AS code_attr, whse_id, whse_desc \
FROM warehouse
sql_attr_uint = code_attr
sql_field_string = whse_id
sql_field_string = whse_desc
}
index warehouse1
{
source = warehouse
path = C:\sphinx\data\warehouse1
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = C:\sphinx\log\searchd.log
query_log = C:\sphinx\log\query.log
read_timeout = 5
max_children = 30
pid_file = C:\sphinx\logsearchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = C:\sphinx\data
}
在我的MariaDB中,我有一个表名'warehouse',其中包含如下字段:
whse_id varchar(8) --> Primary Key
whse_desc varchar(40)
如何解决此错误?请推荐更多有关Sphinx的知识,我应该阅读更多。非常感谢您的帮助
由于错误,第一列应该是您文档的ID。
这里:
sql_query = \
SELECT @id := @id + 1 AS code_attr, whse_id, whse_desc \
FROM warehouse
sql_attr_uint = code_attr
您正在将其分配给属性。这是错误的,如果需要,您需要从数据库中选择ID并单独选择code_attr。
@@ Manticore_Search
我像您这样编辑我的sphinx.conf:
sql_query = \
SELECT id , whse_id, whse_desc \
FROM warehouse
sql_attr_uint = id
sql_field_string = whse_id
sql_field_string = whse_desc
和mariaDB表是这样的:
id bigint(11) --> Primary
whse_id varchar(8)
whse_desc varchar(40)
但错误仍然出现
ERROR: index 'warehouse1': first column in SQL query result must be document ID; found 'id' attribute instead.