使用int主键搜索Sphinx

时间:2017-01-16 13:44:14

标签: sphinx

我尝试将int主键添加为sql_field_string,当我旋转索引时,我收到消息: 警告:属性" purchase_id'没找到 - IGNORING

我的配置:

sp_purchases_source : sp_source_config
{

        sql_query = \
                SELECT sp_purchase.id AS purchase_id, sp_purchase.status, sp_purchase.name, sp_purchase.description_small, sp_purchase.description_full, sp_purchase.news,\
                UNIX_TIMESTAMP(sp_purchase.date_current) AS date_current, UNIX_TIMESTAMP(sp_purchase.stop_date) AS stop_date, sp_purchase.image, sp_purchase.access, \
                sp_purchase.is_vip, sp_purchase.is_foreign, sp_purchase.owner_username, sp_purchase.owner_id, sp_purchase.count_users, sp_purchase.count_comments \
                FROM sp_purchase \
                WHERE sp_purchase.is_hidden = 0 AND sp_purchase.status IN (2,4,17)

        sql_ranged_throttle = 0
        sql_field_string    = purchase_id
        sql_field_string    = name
        sql_field_string    = description_small
        sql_field_string    = description_full
        sql_field_string    = owner_username
        sql_field_string    = news
        sql_attr_timestamp  = date_current
        sql_attr_timestamp  = stop_date
        sql_attr_string     = image
        sql_attr_uint       = access
        sql_attr_uint       = owner_id
        sql_attr_uint       = status
        sql_attr_bool       = is_vip
        sql_attr_bool       = is_foreign
        sql_attr_uint       = count_users
        sql_attr_uint       = count_comments
}

我如何在索引中添加id字段?

1 个答案:

答案 0 :(得分:1)

文档ID是已经一个虚拟属性。它就像一个真实的属性。

因此可以按ID过滤/排序/分组。

sphinxql> SELECT id,name FROM sp_purchases WHERE id BETWEEN 10 and 20;

...要使它成为一个领域,必须有点棘手,例如复制两次。

    sql_query = \
            SELECT sp_purchase.id, sp_purchase.id AS purchase_id, sp_purchase.status, ...

第一列始终是document-id,因此将用于虚拟属性。

因此purchase_id成为'标准'字段。