Only index current vault on Khoj. Remove plugin setting to configure it

- Overview
  Limits using Khoj with a single vault at a time. This is
  automatically configured to the most recently opened vault.

  Once directory filters are supported on backend, the plugin will be
  updated to index multiple vault but search only current vault from
  current vaults khoj obsidian plugin

- Code Details
 - Remove setting to configure Vault directory from Khoj Obsidian plugin
 - Automatically configure Khoj to index only current Vault.
 - Overwrites any previous vaults that were intended to be indexed by
   Khoj backend
 - Force update of index after configuring vault

- Why
  It's not helpful for now and can lead to more problems, confusion.
  Once directory filters
This commit is contained in:
Debanjum Singh Solanky 2023-01-11 03:03:22 -03:00
parent 86a1e43605
commit 4407e23c19
2 changed files with 4 additions and 16 deletions

View file

@ -1,18 +1,15 @@
import { App, Notice, PluginSettingTab, request, Setting } from 'obsidian';
import Khoj from 'src/main';
import { getVaultAbsolutePath } from 'src/utils';
export interface KhojSetting {
resultsCount: number;
khojUrl: string;
obsidianVaultPath: string;
connectedToBackend: boolean;
}
export const DEFAULT_SETTINGS: KhojSetting = {
resultsCount: 6,
khojUrl: 'http://localhost:8000',
obsidianVaultPath: getVaultAbsolutePath(),
connectedToBackend: false,
}
@ -32,15 +29,6 @@ export class KhojSettingTab extends PluginSettingTab {
containerEl.createEl('small', { text: this.getBackendStatusMessage() });
// Add khoj settings configurable from the plugin settings tab
new Setting(containerEl)
.setName('Vault Path')
.setDesc('The Obsidian Vault to search with Khoj')
.addText(text => text
.setValue(`${this.plugin.settings.obsidianVaultPath}`)
.onChange(async (value) => {
this.plugin.settings.obsidianVaultPath = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Khoj URL')
.setDesc('The URL of the Khoj backend')

View file

@ -10,7 +10,7 @@ export function getVaultAbsolutePath(): string {
}
export async function configureKhojBackend(setting: KhojSetting, notify: boolean = true) {
let mdInVault = `${setting.obsidianVaultPath}/**/*.md`;
let mdInVault = `${getVaultAbsolutePath()}/**/*.md`;
let khojConfigUrl = `${setting.khojUrl}/api/config/data`;
// Check if khoj backend is configured, show error if backend is not running
@ -34,7 +34,7 @@ export async function configureKhojBackend(setting: KhojSetting, notify: boolean
// If khoj backend not configured yet
if (!khoj_already_configured) {
// Create khoj content-type config with only markdown configured
let khojObsidianPluginPath = `${setting.obsidianVaultPath}/${this.app.vault.configDir}/plugins/khoj/`;
let khojObsidianPluginPath = `${getVaultAbsolutePath()}/${this.app.vault.configDir}/plugins/khoj/`;
data["content-type"] = {
"markdown": {
"input-filter": [mdInVault],
@ -55,7 +55,7 @@ export async function configureKhojBackend(setting: KhojSetting, notify: boolean
else if (!data["content-type"]["markdown"]) {
// Add markdown config to khoj content-type config
// Set markdown config to index markdown files in configured obsidian vault
let khojObsidianPluginPath = `${setting.obsidianVaultPath}/${this.app.vault.configDir}/plugins/khoj/`;
let khojObsidianPluginPath = `${getVaultAbsolutePath()}/${this.app.vault.configDir}/plugins/khoj/`;
data["content-type"]["markdown"] = {
"input-filter": [mdInVault],
"input-files": null,
@ -99,5 +99,5 @@ export async function updateKhojBackend(khojUrl: string, khojConfig: Object) {
// Save khojConfig on khoj backend at khojConfigUrl
await request(requestContent)
// Refresh khoj search index after updating config
.then(_ => request(`${khojUrl}/api/update?t=markdown`));
.then(_ => request(`${khojUrl}/api/update?t=markdown&force=true`));
}