From b52cd85c76769e82f0d0eb3857cfec63536fe9e3 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 10 Jan 2023 21:59:38 -0300 Subject: [PATCH] Allow Reranking Results using Keybinding from Khoj Search Modal --- src/interface/obsidian/src/modal.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/interface/obsidian/src/modal.ts b/src/interface/obsidian/src/modal.ts index c9eeadde..7653c2bf 100644 --- a/src/interface/obsidian/src/modal.ts +++ b/src/interface/obsidian/src/modal.ts @@ -9,15 +9,29 @@ export interface SearchResult { export class KhojModal extends SuggestModal { setting: KhojSetting; + rerank: boolean; constructor(app: App, setting: KhojSetting) { super(app); this.setting = setting; + this.rerank = false; + + // Register Modal Keybindings to Rerank Results + this.scope.register(['Mod'], 'Enter', async () => { + this.rerank = true + let results = await this.getSuggestions(this.inputEl.value); + + this.resultContainerEl.empty(); + results.forEach((result) => { + this.renderSuggestion(result, this.resultContainerEl); + }); + this.rerank = false + }); } async getSuggestions(query: string): Promise { // Query Khoj backend for search results - var searchUrl = `${this.setting.khojUrl}/api/search?q=${query}&n=${this.setting.resultsCount}&t=markdown` + var searchUrl = `${this.setting.khojUrl}/api/search?q=${query}&n=${this.setting.resultsCount}&r=${this.rerank}&t=markdown` var results = await request(searchUrl) .then(response => JSON.parse(response)) .then(data => {