Skip to content

Commit 4aed27c

Browse files
committed
SearchLite with API & API key.
Search with Oauth2 commented out but works. Have api limited to specific web sites.
1 parent 8665ac5 commit 4aed27c

File tree

2 files changed

+97
-8
lines changed

2 files changed

+97
-8
lines changed

layouts/_default/search.html

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{ define "main" -}}
2+
<script src="{{ "js/marked.min.js" | relURL }}"></script>
23
<section class="row td-search-result">
34
<div class="col-12 col-md-8 offset-md-2">
45
<h2 class="ms-4">{{ .Title }}</h2>
@@ -8,12 +9,52 @@ <h2 class="ms-4">{{ .Title }}</h2>
89
<script>
910
(function() {
1011
const queryText = new URLSearchParams(window.location.search).get('q')
11-
const url = "https://discoveryengine.googleapis.com/v1alpha/projects/85874458559/locations/global/collections/default_collection/engines/interlisp-search_1738386288647/servingConfigs/default_search:answer";
12-
const bearer = "ya29.a0AXeO80SyDRcf-XH1nUUNnoqCezd2vb_ul6hRkfmCk2Tr3zU2PpSdDH0hWeiDPcxg3TV_mFKC3Vz6cNor4iA9A20xs9m_O_mQqa3wCP3nWr3xVir5m8qQeJiLZoGGWYWiolcYkkyBSvNmY8mZnPQXFjA4g_ZheAlB4k4U3ntQcz2wSeRYaCgYKARYSARASFQHGX2MiX_YKbNGIwOUnnouKy41BgA0183"
12+
const url = "https://discoveryengine.googleapis.com/v1alpha/projects/191169864763/locations/global/collections/default_collection/engines/interlisp-search_1741738278473/servingConfigs/default_search:searchLite?key=AIzaSyA_bFZHph5ZXN8EtXTRaQa2zi6Sh70e_zU";
1313
const data = {
14-
query: {
15-
text: `${queryText}`
16-
}
14+
query: `${queryText}`,
15+
pageSize: 20,
16+
session: "projects/191169864763/locations/global/collections/default_collection/engines/interlisp-search_1741738278473/sessions/-",
17+
spellCorrectionSpec: {
18+
mode: "AUTO"
19+
},
20+
languageCode: "en-US",
21+
contentSearchSpec: {
22+
snippetSpec: {
23+
returnSnippet: true
24+
}
25+
}
26+
};
27+
fetch(url, {
28+
method: "POST",
29+
headers: {
30+
"Content-Type": "application/json"
31+
},
32+
body: JSON.stringify(data)
33+
})
34+
.then(response => response.json())
35+
.then(data => {
36+
console.log("debug info fetch 66", data);
37+
const resultDiv2 = document.createElement('div');
38+
resultDiv2.innerHTML = marked.parse(data.answer.answerText); // Use a Markdown parser like "marked" to render Markdown as HTML
39+
document.querySelector('.col-12.col-md-8.offset-md-2').appendChild(resultDiv2);
40+
})
41+
/*
42+
This method requires Oauth2 authentication and a valid bearer token.
43+
const url = "https://discoveryengine.googleapis.com/v1alpha/projects/191169864763/locations/global/collections/default_collection/engines/interlisp-search_1741738278473/servingConfigs/default_search:search";
44+
const bearer = "ya29.a0AZYkNZjwU1i01Y9FG5PK1G-3W9OlUGIpbqN87t35wfNBwNRILQIsXdxT34ABzJDpaWsnhsUiImHR5smDsxxgdYcX0x6e07KjoqDic0XVhzE6_dflLQ0p84-_BKYA2latAOTGhDvVHYKGY_sa5taCIEndv6yGIcHwOKX977TiZQyzfL4aCgYKAZcSARESFQHGX2MitMARmJuZ1CbwkvQbfN151w0182";
45+
const data = {
46+
query: `${queryText}`,
47+
pageSize: 10,
48+
session: "projects/191169864763/locations/global/collections/default_collection/engines/interlisp-search_1741738278473/sessions/-",
49+
spellCorrectionSpec: {
50+
mode: "AUTO"
51+
},
52+
languageCode: "en-US",
53+
contentSearchSpec: {
54+
snippetSpec: {
55+
returnSnippet: true
56+
}
57+
}
1758
};
1859
1960
fetch(url, {
@@ -26,10 +67,52 @@ <h2 class="ms-4">{{ .Title }}</h2>
2667
})
2768
.then(response => response.json())
2869
.then(data => {
70+
console.log("debug info fetch 28", data);
2971
const resultDiv = document.createElement('div');
30-
resultDiv.textContent = JSON.stringify(data, null, 2);
31-
document.querySelector('.col-12.col-md-8.offset-md-2').appendChild(resultDiv);
32-
})
72+
// resultDiv.textContent = JSON.stringify(data, null, 2);
73+
// document.querySelector('.col-12.col-md-8.offset-md-2').appendChild(resultDiv);
74+
const resultsCall1 = data; // Define resultsCall1 here
75+
const url2 = "https://discoveryengine.googleapis.com/v1alpha/projects/191169864763/locations/global/collections/default_collection/engines/interlisp-search_1741738278473/servingConfigs/default_search:answer";
76+
const data2 = {
77+
query : {
78+
text: `${queryText}`,
79+
queryId: `${resultsCall1.sessionInfo.queryId}` // Fix typo here
80+
},
81+
session: `${resultsCall1.sessionInfo.name}`,
82+
relatedQuestionsSpec: {
83+
enable: true
84+
},
85+
answerGenerationSpec: {
86+
ignoreAdversarialQuery: false,
87+
ignoreNonAnswerSeekingQuery: false,
88+
ignoreLowRelevantContent: true,
89+
multimodalSpec: {},
90+
includeCitations: true,
91+
promptSpec: {
92+
preamble: "You are a researcher with experience in computer science and the evolution of programming languages. Answers should be targeted for like-minded individuals. Technical details are good, especially when they are appropriately attributed."
93+
},
94+
modelSpec: {
95+
modelVersion: "stable"
96+
}
97+
}
98+
};
99+
console.log("debug POST 2 body: ", data2);
100+
fetch(url2, {
101+
method: "POST",
102+
headers: {
103+
"Content-Type": "application/json",
104+
"Authorization": `Bearer ${bearer}`
105+
},
106+
body: JSON.stringify(data2)
107+
})
108+
.then(response => response.json())
109+
.then(data => {
110+
console.log("debug info fetch 66", data);
111+
const resultDiv2 = document.createElement('div');
112+
resultDiv2.innerHTML = marked.parse(data.answer.answerText); // Use a Markdown parser like "marked" to render Markdown as HTML
113+
document.querySelector('.col-12.col-md-8.offset-md-2').appendChild(resultDiv2);
114+
})
115+
}) */
33116
.catch(error => {
34117
console.error("Failed to fetch remote resource:", error);
35118
});

0 commit comments

Comments
 (0)