使用索引名称扩展 sphinx 搜索输出
Extend sphinx search output with index names
我有 2 个 sphinx 索引:index1
和 index2
。
当我在 index1
中搜索时:我有两个匹配项:
{ 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 条记录并 return 到客户端。
当我在 index2
中搜索相同的词时:我找到了三个匹配项:
{ 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 条记录并 return 到客户端。
当我在所有索引中搜索时,我得到了五个记录:
{ 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
s 引用不同的表。
如何获取包含搜索结果或来源的索引名称或其他信息以确切了解已找到的内容?
如果重要的话,我正在使用 sphinxapi node.js 客户端。
向索引添加显式属性:)
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中的数字为属性的位数)
我有 2 个 sphinx 索引:index1
和 index2
。
当我在 index1
中搜索时:我有两个匹配项:
{ 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 条记录并 return 到客户端。
当我在 index2
中搜索相同的词时:我找到了三个匹配项:
{ 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 条记录并 return 到客户端。
当我在所有索引中搜索时,我得到了五个记录:
{ 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
s 引用不同的表。
如何获取包含搜索结果或来源的索引名称或其他信息以确切了解已找到的内容?
如果重要的话,我正在使用 sphinxapi node.js 客户端。
向索引添加显式属性:)
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中的数字为属性的位数)