mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Extract search request URL builder into js function in web interface
This commit is contained in:
@@ -93,15 +93,8 @@
|
|||||||
if (rerank)
|
if (rerank)
|
||||||
setQueryFieldInUrl(query);
|
setQueryFieldInUrl(query);
|
||||||
|
|
||||||
// Generate Backend API URL to execute Search
|
|
||||||
if (type == 'all')
|
|
||||||
url = `/api/search?q=${encodeURIComponent(query)}&n=${results_count}&client=web`;
|
|
||||||
else if (type === "image")
|
|
||||||
url = `/api/search?q=${encodeURIComponent(query)}&t=${type}&n=${results_count}&client=web`;
|
|
||||||
else
|
|
||||||
url = `/api/search?q=${encodeURIComponent(query)}&t=${type}&n=${results_count}&r=${rerank}&client=web`;
|
|
||||||
|
|
||||||
// Execute Search and Render Results
|
// Execute Search and Render Results
|
||||||
|
url = createRequestUrl(query, type, results_count, rerank);
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@@ -157,6 +150,18 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createRequestUrl(query, results_count, type, rerank) {
|
||||||
|
// Generate Backend API URL to execute Search
|
||||||
|
let url = `/api/search?q=${encodeURIComponent(query)}&n=${results_count}&client=web`;
|
||||||
|
// If type is not 'all', append type to URL
|
||||||
|
if (type !== 'all')
|
||||||
|
url += `&t=${type}`;
|
||||||
|
// Rerank is only supported by text types
|
||||||
|
if (type !== "image")
|
||||||
|
url += `&r=${rerank}`;
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
function setTypeFieldInUrl(type) {
|
function setTypeFieldInUrl(type) {
|
||||||
var url = new URL(window.location.href);
|
var url = new URL(window.location.href);
|
||||||
url.searchParams.set("t", type.value);
|
url.searchParams.set("t", type.value);
|
||||||
|
|||||||
Reference in New Issue
Block a user