mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 13:21:18 +00:00
Allow Reranking Results using Keybinding from Khoj Search Modal
This commit is contained in:
@@ -9,15 +9,29 @@ export interface SearchResult {
|
|||||||
|
|
||||||
export class KhojModal extends SuggestModal<SearchResult> {
|
export class KhojModal extends SuggestModal<SearchResult> {
|
||||||
setting: KhojSetting;
|
setting: KhojSetting;
|
||||||
|
rerank: boolean;
|
||||||
|
|
||||||
constructor(app: App, setting: KhojSetting) {
|
constructor(app: App, setting: KhojSetting) {
|
||||||
super(app);
|
super(app);
|
||||||
this.setting = setting;
|
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<SearchResult[]> {
|
async getSuggestions(query: string): Promise<SearchResult[]> {
|
||||||
// Query Khoj backend for search results
|
// 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)
|
var results = await request(searchUrl)
|
||||||
.then(response => JSON.parse(response))
|
.then(response => JSON.parse(response))
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
Reference in New Issue
Block a user