You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
855 B
JavaScript
36 lines
855 B
JavaScript
2 years ago
|
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());
|
||
|
}
|
||
|
|
||
|
function debounce(func, timeout = 300) {
|
||
|
let timer;
|
||
|
return (...args) => {
|
||
|
clearTimeout(timer)
|
||
|
timer = setTimeout(() => { func.apply(this, args); }, timeout)
|
||
|
};
|
||
|
}
|
||
|
|
||
|
registerHandlers(debounce((e) => {
|
||
|
term = e.target.value
|
||
|
searchContents(term)
|
||
|
.then((res) => res.results.map(entry => ({
|
||
|
url: entry.object.metadata.url,
|
||
|
content: entry.snippet,
|
||
|
title: entry.object.title
|
||
|
})))
|
||
|
.then(results => displayResults(results))
|
||
|
}))
|