feat: add support for semantic search using operand
parent
14b89105dc
commit
5ef9aad501
@ -0,0 +1,35 @@
|
||||
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))
|
||||
}))
|
@ -1,3 +1,3 @@
|
||||
{{if $.Site.Data.config.enableGitHubEdit}}
|
||||
<a href="{{$.Site.Data.config.GitHubLink}}/{{.Path}}" rel="noopener">Edit Source</a>
|
||||
<a href="{{$.Site.Data.config.GitHubLink}}/{{.File.Path}}" rel="noopener">Edit Source</a>
|
||||
{{end}}
|
||||
|
Loading…
Reference in New Issue