如何在 azure search suggesters 上使用 select
How to use select on azure search suggesters
我在我的项目中使用 Azure 搜索,我想做一个自动完成的文本字段,它按预期工作。这是代码:
const suggestItems = async (req, res) => {
try {
// Reading inputs from HTTP Request
const q = (req.query.q || (req.body && req.body.q));
const top = (req.query.top || (req.body && req.body.top));
const suggester = (req.query.suggester || (req.body && req.body.suggester));
// Let's get the top 5 suggestions for that search term
const suggestions = await client.suggest(q, suggester, { top: parseInt(top) });
//const suggestions = await client.autocomplete(q, suggester, {top: parseInt(top)});
console.log(suggestions.results)
return res.status(status.OK)
.json({ suggestions: suggestions.results})
} catch (error) {
handleError(res, error)
}
}
她的结果:
[
{ text: 'Alpha Aromatics (MA)', document: { id: '4' } },
{ text: 'Alpha Aromatics (USA)', document: { id: '5' } },
{ text: 'Art Land - Winter Palace', document: { id: '6' } },
{ text: 'Alpha Aromatics (USA)', document: { id: '3' } }
]
这是邮递员传递的问题:
{
"q":"ar","top":5,"suggester":"sg"
}
但问题是,结果我只有文档的文本和 ID,我正在寻找其他字段,例如状态,请问如何获得?
根据问题,我猜“状态”是您的索引字段之一。您需要确保在索引定义中将需要在结果中返回的字段标记为 retrievable
。看起来您只有文本和 ID 字段 retrievable
。更多信息:https://docs.microsoft.com/en-us/azure/search/search-what-is-an-index.
示例:
我在我的项目中使用 Azure 搜索,我想做一个自动完成的文本字段,它按预期工作。这是代码:
const suggestItems = async (req, res) => {
try {
// Reading inputs from HTTP Request
const q = (req.query.q || (req.body && req.body.q));
const top = (req.query.top || (req.body && req.body.top));
const suggester = (req.query.suggester || (req.body && req.body.suggester));
// Let's get the top 5 suggestions for that search term
const suggestions = await client.suggest(q, suggester, { top: parseInt(top) });
//const suggestions = await client.autocomplete(q, suggester, {top: parseInt(top)});
console.log(suggestions.results)
return res.status(status.OK)
.json({ suggestions: suggestions.results})
} catch (error) {
handleError(res, error)
}
}
她的结果:
[
{ text: 'Alpha Aromatics (MA)', document: { id: '4' } },
{ text: 'Alpha Aromatics (USA)', document: { id: '5' } },
{ text: 'Art Land - Winter Palace', document: { id: '6' } },
{ text: 'Alpha Aromatics (USA)', document: { id: '3' } }
]
这是邮递员传递的问题:
{
"q":"ar","top":5,"suggester":"sg"
}
但问题是,结果我只有文档的文本和 ID,我正在寻找其他字段,例如状态,请问如何获得?
根据问题,我猜“状态”是您的索引字段之一。您需要确保在索引定义中将需要在结果中返回的字段标记为 retrievable
。看起来您只有文本和 ID 字段 retrievable
。更多信息:https://docs.microsoft.com/en-us/azure/search/search-what-is-an-index.
示例: