0

我是 Sphinx 的新手,并尝试在 sphinx.conf 中设置“索引”。

当我运行命令“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 中,我有一个表名“仓库”,其中包含如下字段:

whse_id   varchar(8) --> Primary Key
whse_desc varchar(40)

我该如何解决这个错误?请推荐更多狮身人面像知识我应该阅读更多。非常感谢你的帮助

4

2 回答 2

0

@Manticore 搜索

我像你提到的那样编辑我的 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) unsigned --> 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.
于 2020-06-10T03:49:02.287 回答
0

正如错误所说,第一列应该是您文档的 id。

这里:

    sql_query       = \
        SELECT @id := @id + 1 AS code_attr, whse_id, whse_desc \
        FROM warehouse

    sql_attr_uint   = code_attr

您正在将其分配给属性。这是错误的,如果需要,您需要从 db 中选择 id 和单独的 code_attr。

于 2020-06-10T02:40:25.687 回答