2016-10-20 5 views
0

私は2つのスフィンクスインデックス:index1index2を持っています。インデックス名を含むスフィンクス検索出力を拡張する

私はindex1で検索:今、私は、データベースからこれらの2つのレコードを取得し、クライアントに返すことができ

{ error: '', 
    warning: '', 
    status: [ 0 ], 
    fields: [ 'name' ], 
    attrs: [], 
    matches: 
    [ { id: 5731, weight: 2, attrs: {} }, 
    { id: 17236, weight: 2, attrs: {} } ], 
    total: 2, 
    total_found: 2, 
    time: 0, 
    words: [ { word: '*foo*', docs: 2, hits: 4 } ] } 

:私は2つの試合を持っています。

私はindex2で同じ用語を検索します。今、私は、データベースからこれらの3つのレコードを取得し、クライアントに返すことができ

{ error: '', 
    warning: '', 
    status: [ 0 ], 
    fields: [ 'name' ], 
    attrs: [], 
    matches: 
    [ { id: 28, weight: 1, attrs: {} }, 
    { id: 41, weight: 1, attrs: {} }, 
    { id: 42, weight: 1, attrs: {} } ], 
    total: 3, 
    total_found: 3, 
    time: 0, 
    words: [ { word: '*foo*', docs: 3, hits: 3 } ] } 

:私は3つの試合を持っています。

私は、私は5つのレコード持っているすべてのインデックスで検索する場合:

{ error: '', 
    warning: '', 
    status: [ 0 ], 
    fields: [ 'name' ], 
    attrs: [], 
    matches: 
    [ { id: 5731, weight: 2, attrs: {} }, 
    { id: 17236, weight: 2, attrs: {} }, 
    { id: 28, weight: 1, attrs: {} }, 
    { id: 41, weight: 1, attrs: {} }, 
    { id: 42, weight: 1, attrs: {} } ], 
    total: 5, 
    total_found: 5, 
    time: 0, 
    words: [ { word: '*foo*', docs: 5, hits: 7 } ] } 

を問題は、インデックスが異なるデータベーステーブルの上に構築されます。だから私は実際に一致と何をするかわからないid異なるテーブルへの参照を引き起こします。

検索結果やソースなどでインデックス名を取得するには、どうすればよいでしょうか?

私はsphinxapi node.jsクライアントを使用しています。

+0

を私はスフィンクスに新たなんです。ダミーの質問に申し訳ありません、私は本当にそれをGoogleにしようとしました –

答えて

1

はインデックスに明示的な属性を追加します:)

source index1 { 
    sql_query = SELECT id, title, 1 as idx FROM ... 
    sql_attr_uint = idx:2 

source index2 { 
    sql_query = SELECT id, title, 2 as idx FROM ... 
    sql_attr_uint = idx:2 

(sql_attr_uint内の数字は、属性のビット数である)

関連する問題