From 1da44d4dfea4a7943ee074ea4485806344a698f6 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Thu, 28 Jul 2022 04:31:24 +0400 Subject: [PATCH] Add Incremental Search to Khoj Web Interface --- src/interface/web/index.html | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/interface/web/index.html b/src/interface/web/index.html index dce7548f..59c9ea9a 100644 --- a/src/interface/web/index.html +++ b/src/interface/web/index.html @@ -18,16 +18,19 @@ return `
${JSON.stringify(data, null, 2)}
` } - function search() { + function search(rerank=false) { query = document.getElementById("query").value; type = document.getElementById("type").value; console.log(query, type); - fetch(`/search?q=${query}&t=${type}&n=6`) + url = type === "image" + ? `/search?q=${query}&t=${type}&n=6` + : `/search?q=${query}&t=${type}&n=6&r=${rerank}`; + fetch(url) .then(response => response.json()) .then(data => { console.log(data); document.getElementById("results").innerHTML = - type == "image" + type === "image" ? data.map(render_image).join('') : render_json(data); }); @@ -44,9 +47,14 @@ }); } - function search_on_enter(event) { - if (event.key == 'Enter') { - search(); + function incremental_search(event) { + type = document.getElementById("type").value; + if (event.key === 'Enter') { + search(rerank=true); + } + // Limit incremental search to text types + else if (type !== "image") { + search(rerank=false); } } @@ -54,8 +62,8 @@

Khoj

- - + + -