From 77672ac0aede45165fce6b0dada60b1bf48f8790 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Thu, 29 Jun 2023 14:14:25 -0700 Subject: [PATCH] Demarcate different results with a border box - Add back support for searching by type Github - Remove custom class name in markdown js file --- .../interface/web/assets/markdown-it.min.js | 10 --- src/khoj/interface/web/index.html | 72 +++++++++++-------- src/khoj/processor/github/github_to_jsonl.py | 3 +- src/khoj/routers/api.py | 14 ++++ 4 files changed, 60 insertions(+), 39 deletions(-) diff --git a/src/khoj/interface/web/assets/markdown-it.min.js b/src/khoj/interface/web/assets/markdown-it.min.js index 7339517f..5b37e28e 100644 --- a/src/khoj/interface/web/assets/markdown-it.min.js +++ b/src/khoj/interface/web/assets/markdown-it.min.js @@ -3227,16 +3227,6 @@ result += (token.nesting === -1 ? "` + md.render(`${item.entry}`) + ``; + else { + rendered = md.render(`${item.entry}`); + } + return `
` + rendered + `
`; }).join("\n"); } @@ -59,29 +63,22 @@ }).join("\n"); } - function render_mutliple(query, data, type) { - let org_files = data.filter((item) => item.additional.file.endsWith(".org")); - let md_files = data.filter((item) => item.additional.file.endsWith(".md")); - let pdf_files = data.filter((item) => item.additional.file.endsWith(".pdf")); - let issue_files = data.filter((item) => item.additional.file.includes("issues") && item.additional.file.includes("github.com")); - + function render_multiple(query, data, type) { let html = ""; - if (org_files.length > 0) { - html += render_org(query, org_files, type); - } - - if (md_files.length > 0) { - html += render_markdown(query, md_files); - } - - if (issue_files.length > 0) { - html += render_markdown(query, issue_files); - } - - if (pdf_files.length > 0) { - html += render_pdf(query, pdf_files); - } - + data.forEach(item => { + if (item.additional.file.endsWith(".org")) { + html += render_org(query, [item], "org-"); + } else if ( + item.additional.file.endsWith(".md") || + item.additional.file.endsWith(".markdown") || + (item.additional.file.includes("issues") && item.additional.file.includes("github.com")) + ) + { + html += render_markdown(query, [item]); + } else if (item.additional.file.endsWith(".pdf")) { + html += render_pdf(query, [item]); + } + }); return html; } @@ -100,11 +97,25 @@ } else if (type === "pdf") { results = render_pdf(query, data); } else if (type === "github" || type === "all") { - results = render_mutliple(query, data, type); + results = render_multiple(query, data, type); } else { results = data.map((item) => `
` + `

${item.entry}

` + `
`).join("\n") } - return `
${results}
`; + + // Any POST rendering goes here. + + let renderedResults = document.createElement("div"); + renderedResults.id = `results-${type}`; + renderedResults.innerHTML = results; + + // For all elements that are of type img in the results html and have a src with 'avatar' in the URL, add the class 'avatar' + // This is used to make the avatar images round + let images = renderedResults.querySelectorAll("img[src*='avatar']"); + for (let i = 0; i < images.length; i++) { + images[i].classList.add("avatar"); + } + + return renderedResults.outerHTML; } function search(rerank=false) { @@ -277,7 +288,6 @@ margin: 0px; background: #f8fafc; color: #475569; - text-align: center; font-family: roboto, karma, segoe ui, sans-serif; font-size: 20px; font-weight: 300; @@ -388,12 +398,18 @@ text-decoration: none; } - img.md-avatar { + img.avatar { width: 20px; height: 20px; border-radius: 50%; } + div.results-markdown, + div.results-org, + div.results-pdf { + border: black 1px solid; + } + diff --git a/src/khoj/processor/github/github_to_jsonl.py b/src/khoj/processor/github/github_to_jsonl.py index 69f7033c..e94749f1 100644 --- a/src/khoj/processor/github/github_to_jsonl.py +++ b/src/khoj/processor/github/github_to_jsonl.py @@ -1,6 +1,7 @@ # Standard Packages import logging import time +from datetime import datetime from typing import Dict, List, Union # External Packages @@ -235,7 +236,7 @@ class GithubToJsonl(TextToJsonl): return result for comment in raw_comments: - created_at = comment["created_at"].split("T")[0] + created_at = datetime.strptime(comment["created_at"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H:%M") commenter = comment["user"]["login"] commenter_url = comment["user"]["html_url"] comment_url = comment["html_url"] diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index 9069418b..980ab1fb 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -216,6 +216,20 @@ async def search( ) ] + if (t == SearchType.Github or t == SearchType.All) and state.model.github_search: + # query github issues + search_futures += [ + executor.submit( + text_search.query, + user_query, + state.model.github_search, + question_embedding=encoded_asymmetric_query, + rank_results=r or False, + score_threshold=score_threshold, + dedupe=dedupe or True, + ) + ] + if (t == SearchType.Pdf or t == SearchType.All) and state.model.pdf_search: # query pdf files search_futures += [