0

I have 2 sphinx indexes: index1 and index2.

When I search in index1: I've got two matches:

{ 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 } ] }

Now I can fetch those 2 records from database and return to client.

When I search same term in index2: I've got three matches:

{ 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 } ] }

Now I can fetch those 3 records from database and return to client.

When I search in all indexes I've got five records:

{ 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 } ] }

The problem is indexes build on different database tables. So I don't know actually what to do with matches cause ids reference to different tables.

How can I get index names with search results or sources or something to know what exactly have been found?

I'm using sphinxapi node.js client if it matters.

Boris Zagoruiko
  • 12,705
  • 15
  • 47
  • 79

1 Answers1

2

Add an explicit attribute to the indexes :)

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

(the number in sql_attr_uint is the number of bits for the attribute)

barryhunter
  • 20,886
  • 3
  • 30
  • 43