【问题标题】:How to use subquery In Sphinx's multi-valued attributes (MVA) for query type如何在 Sphinx 的多值属性 (MVA) 中使用子查询作为查询类型
【发布时间】:2016-05-14 06:40:43
【问题描述】:

我的数据库是 PostgreSQL,我想使用 Sphinx 搜索引擎来索引我的数据;

如何使用sql_attr_multi 获取关系数据?

postgresql 中的表,schema 是:

crm=# \d orders
                                   Table "orders"
     Column      |            Type             |               Modifiers
-----------------+-----------------------------+----------------------------------------
 id              | bigint                      | not null
 trade_id        | bigint                      | not null
 item_id         | bigint                      | not null
 price           | numeric(10,2)               | not null
 total_amount    | numeric(10,2)               | not null
 subject         | character varying(255)      | not null default ''::character varying
 status          | smallint                    | not null default 0
 created_at      | timestamp without time zone | not null default now()
 updated_at      | timestamp without time zone | not null default now()
Indexes:
    "orders_pkey" PRIMARY KEY, btree (id)
    "orders_trade_id_idx" btree (trade_id)




crm=# \d trades
                                     Table "trades"
        Column         |            Type             |               Modifiers
-----------------------+-----------------------------+---------------------------------------
 id                    | bigint                      | not null
 operator_id           | bigint                      | not null
 customer_id           | bigint                      | not null
 category_ids          | bigint[]                    | not null
 total_amount          | numeric(10,2)               | not null
 discount_amount       | numeric(10,2)               | not null
 created_at            | timestamp without time zone | not null default now()
 updated_at            | timestamp without time zone | not null default now()
Indexes:
    "trades_pkey" PRIMARY KEY, btree (id)

狮身人面像的配置是:

source trades_src
{
  type        = pgsql
  sql_host    = 10.10.10.10
  sql_user    = ******
  sql_pass    = ******
  sql_db      = crm
  sql_port    = 5432

  sql_query   = \
    SELECT id, operator_id, customer_id, category_ids, total_amount, discount_amount, \
         date_part('epoch',created_at) AS created_at, \
         date_part('epoch',updated_at) AS updated_at \
      FROM public.trades;

  #attributes
  sql_attr_bigint = operator_id
  sql_attr_bigint = customer_id

  sql_attr_float  = total_amount
  sql_attr_float  = discount_amount


  sql_attr_multi = bigint category_ids from field category_ids

  #sql_attr_multi = bigint order_ids from query; SELECT id FROM orders
  #how can i add where condition is the query for orders? eg. WHERE trade_id = ?


  sql_attr_timestamp  = created_at
  sql_attr_timestamp  = updated_at
}

我在category_ids字段上使用了MVA (multi-valued attributes),它是Postgresql中的ARRAY类型。

但我不知道如何在 order_ids 上定义 MVA。会通过子查询吗?

【问题讨论】:

    标签: postgresql subquery search-engine sphinx


    【解决方案1】:

    从狮身人面像论坛复制....

    sql_attr_multi = bigint order_ids from query; SELECT trade_id,id FROM orders ORDER BY trade_id
    

    查询的第一列是狮身人面像'document_id'(即主sql_query中的id

    第二列是要插入到该文档的 MVA 数组中的值。

    ORDER BY 可能并不严格需要,但如果按 document_id IIRC 排序,sphinx 处理数据的速度要快得多)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      • 2012-04-06
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      相关资源
      最近更新 更多