2016-05-13 21 views
0

Meine Datenbank ist PostgreSQL, und ich möchte Sphinx Search Engines verwenden, um meine Daten zu indizieren;Verwendung der Unterabfrage In den mehrwertigen Attributen (MVA) von Sphinx für die Abfrage

Wie kann ich sql_attr_multi verwenden, um die Beziehungsdaten abzurufen?

Die Tabellen in postgresql, Schemata ist:

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) 

Die config Sphinx ist:

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 
} 

I MVA (multi-valued attributes) auf category_ids Feld verwendet wird, und es ist der Typ ARRAY in Postgresql.

Aber ich weiß nicht Wie MVA auf order_ids zu definieren. Es wird durch Unterabfrage sein?

Antwort

1

von Sphinx forum kopiert ....

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

Die erste Spalte der Abfrage ist das Sphinx DOCUMENT_ID '(dh die id in Haupt sql_query)

der zweiten Spalte wird der Wert auf Einfügen in das MVA-Array für das Dokument.

(Die ORDER BY nicht unbedingt erforderlich sein könnten, aber Sphinx ist viel schneller bei der Verarbeitung der Daten, wenn sie von document_id IIRC bestellt)

+0

Danke mach variieren :) es funktionierte gut – Fish