mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Allow Reranking Results using Keybinding from Khoj Search Modal
This commit is contained in:
parent
7991ab7a86
commit
b52cd85c76
1 changed files with 15 additions and 1 deletions
|
@ -9,15 +9,29 @@ export interface SearchResult {
|
|||
|
||||
export class KhojModal extends SuggestModal<SearchResult> {
|
||||
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<SearchResult[]> {
|
||||
// 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 => {
|
||||
|
|
Loading…
Reference in a new issue