2016-05-13 8 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の配列型です。

しかし、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_queryですなわちid)である

2列目は値でありますそのドキュメントのMVA配列に挿入します。

ORDER BYは厳密には必要ではないかもしれないが、DOCUMENT_IDのIIRCで注文した場合のスフィンクスは、データを処理する時に非常に高速です)

+0

あなたはマッハを変えるありがとう:)それがうまく働きました – Fish

関連する問題