2016-05-13 89 views
0

我的數據庫是PostgreSQL和我想用獅身人面像搜索引擎索引我的數據;如何使用子查詢在獅身人面像的多值屬性(MVA)的查詢類型

如何使用sql_attr_multi獲取關係的數據?

PostgreSQL中的表,模式是:

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數組類型。

但我知道DONOT如何在order_ids定義MVA。這將通過子查詢?

回答

1

從斯芬克斯論壇複製....

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

查詢的第一列是斯芬克斯「DOCUMENT_ID」(即,在主sql_queryid

第二列是值以插入到該文檔的MVA數組中。

(該ORDER BY可能不嚴格是必要的,但如果由DOCUMENT_ID IIRC有序斯芬克斯是在處理數據更快)

+0

謝謝你改變馬赫:)它工作得很好 – Fish