From e9aa6ae9e7ec1792b11ebcb6cac606c47ae3cf7d Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 20 Nov 2022 23:09:58 +0000
Subject: [PATCH] feat: docker docs, semantic search alpha
---
assets/js/semantic-search.js | 53 ++++++++++++++++++++++++++++++++---------------------
1 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/assets/js/semantic-search.js b/assets/js/semantic-search.js
index a62d3d5..ec28d53 100644
--- a/assets/js/semantic-search.js
+++ b/assets/js/semantic-search.js
@@ -1,21 +1,29 @@
-const apiKey = "{{$.Site.Data.config.operandApiKey}}"
+import {
+ operandClient,
+ indexIDHeaderKey,
+} from "https://unpkg.com/@operandinc/sdk@4.1.3/dist/esm/index.js"
+
+const apiKey = "{{$.Site.Data.config.search.operandApiKey}}"
+const indexId = "{{$.Site.Data.config.search.operandIndexId}}"
+const operand = operandClient(
+ ObjectService,
+ apiKey,
+ "https://api.operand.ai",
+ {
+ [indexIDHeaderKey]: indexId,
+ }
+);
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());
+ const results = await operand.searchWithin({
+ query,
+ limit: 10,
+ })
+ console.log(results.matches)
+ return results.matches.flat()
}
-function debounce(func, timeout = 300) {
+function debounce(func, timeout = 200) {
let timer;
return (...args) => {
clearTimeout(timer)
@@ -25,11 +33,14 @@
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))
+ 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))
+ }
}))
--
Gitblit v1.10.0