mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 13:19:16 +00:00
Extract search request URL builder into js function in web interface
This commit is contained in:
@@ -93,15 +93,8 @@
|
||||
if (rerank)
|
||||
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
|
||||
url = createRequestUrl(query, type, results_count, rerank);
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.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) {
|
||||
var url = new URL(window.location.href);
|
||||
url.searchParams.set("t", type.value);
|
||||
|
||||
Reference in New Issue
Block a user