Na svém projektu používám Azure search a chci udělat textové pole automatického doplňování, funguje to podle očekávání. zde je kód:
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) } }
ona je výsledek :
[ { 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' } } ]
zde je dotaz, který prošel pošťákem:
{ "q":"ar","top":5,"suggester":"sg" }
ale problém je v tom, že ve výsledku mám jen text a id dokumentu, hledám další pole, jako je například stav, jak to prosím mohu získat?
Odpověď
Hádám, že „Stav“ je jedním z vašich indexových polí z otázky. Musíte se ujistit, že jste ve výsledcích označili pole, která mají být vrácena, jako retrievable
ve vaší definici indexu. Zdá se, že máte pouze textová a id pole jako retrievable
. Další informace:https://docs.microsoft.com/en-us/azure/search/search-what-is-an-index.
Příklad: