2022-08-01 02:16:36 +07:00
|
|
|
const apiKey = "{{$.Site.Data.config.operandApiKey}}"
|
|
|
|
|
|
|
|
async function searchContents(query) {
|
|
|
|
const response = await fetch('https://prod.operand.ai/v3/search/objects', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: apiKey,
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
query,
|
|
|
|
max: 10
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
return (await response.json());
|
|
|
|
}
|
|
|
|
|
2022-08-01 08:02:06 +07:00
|
|
|
registerHandlers((e) => {
|
2022-08-01 02:16:36 +07:00
|
|
|
term = e.target.value
|
2022-08-01 06:55:25 +07:00
|
|
|
if (term !== "") {
|
|
|
|
searchContents(term)
|
|
|
|
.then((res) => res.results.map(entry => ({
|
|
|
|
url: entry.object.properties.url,
|
|
|
|
content: entry.snippet,
|
|
|
|
title: entry.object.metadata.title
|
|
|
|
})
|
|
|
|
))
|
|
|
|
.then(results => displayResults(results))
|
|
|
|
}
|
2022-08-01 08:02:06 +07:00
|
|
|
})
|