Displaying different indexing steps while Omnisearch is loading
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
import { onDestroy, onMount, tick } from 'svelte'
|
import { onDestroy, onMount, tick } from 'svelte'
|
||||||
import InputSearch from './InputSearch.svelte'
|
import InputSearch from './InputSearch.svelte'
|
||||||
import ModalContainer from './ModalContainer.svelte'
|
import ModalContainer from './ModalContainer.svelte'
|
||||||
import { eventBus, type ResultNote } from 'src/globals'
|
import { eventBus, IndexingStep, type ResultNote } from 'src/globals'
|
||||||
import { createNote, openNote } from 'src/tools/notes'
|
import { createNote, openNote } from 'src/tools/notes'
|
||||||
import { SearchEngine } from 'src/search/search-engine'
|
import { SearchEngine } from 'src/search/search-engine'
|
||||||
import { getCtrlKeyLabel, getExtension, loopIndex } from 'src/tools/utils'
|
import { getCtrlKeyLabel, getExtension, loopIndex } from 'src/tools/utils'
|
||||||
@@ -24,7 +24,8 @@
|
|||||||
let searchQuery: string | undefined
|
let searchQuery: string | undefined
|
||||||
let resultNotes: ResultNote[] = []
|
let resultNotes: ResultNote[] = []
|
||||||
let query: Query
|
let query: Query
|
||||||
let { isIndexing } = SearchEngine
|
let { indexingStep } = SearchEngine
|
||||||
|
let indexingStepDesc = ''
|
||||||
|
|
||||||
$: selectedNote = resultNotes[selectedIndex]
|
$: selectedNote = resultNotes[selectedIndex]
|
||||||
$: searchQuery = searchQuery ?? previousQuery
|
$: searchQuery = searchQuery ?? previousQuery
|
||||||
@@ -33,6 +34,30 @@
|
|||||||
} else {
|
} else {
|
||||||
resultNotes = []
|
resultNotes = []
|
||||||
}
|
}
|
||||||
|
$: {
|
||||||
|
switch ($indexingStep) {
|
||||||
|
case IndexingStep.LoadingCache:
|
||||||
|
indexingStepDesc = 'Loading cache...'
|
||||||
|
break
|
||||||
|
case IndexingStep.ReadingNotes:
|
||||||
|
updateResults()
|
||||||
|
indexingStepDesc = 'Reading notes...'
|
||||||
|
break
|
||||||
|
case IndexingStep.ReadingPDFs:
|
||||||
|
indexingStepDesc = 'Reading PDFs...'
|
||||||
|
break
|
||||||
|
case IndexingStep.ReadingImages:
|
||||||
|
indexingStepDesc = 'Reading images...'
|
||||||
|
break
|
||||||
|
case IndexingStep.UpdatingCache:
|
||||||
|
indexingStepDesc = 'Updating cache...'
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
updateResults()
|
||||||
|
indexingStepDesc = ''
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
eventBus.enable('vault')
|
eventBus.enable('vault')
|
||||||
@@ -211,9 +236,9 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</InputSearch>
|
</InputSearch>
|
||||||
|
|
||||||
{#if $isIndexing}
|
{#if indexingStepDesc}
|
||||||
<div style="text-align: center; color: var(--text-accent); margin-top: 10px">
|
<div style="text-align: center; color: var(--text-accent); margin-top: 10px">
|
||||||
⏳ Omnisearch indexing is currently in progress
|
⏳ Work in progress: {indexingStepDesc}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ export const EventNames = {
|
|||||||
ToggleExcerpts: 'toggle-excerpts',
|
ToggleExcerpts: 'toggle-excerpts',
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
|
export const enum IndexingStep {
|
||||||
|
Done,
|
||||||
|
LoadingCache,
|
||||||
|
ReadingNotes,
|
||||||
|
ReadingPDFs,
|
||||||
|
ReadingImages,
|
||||||
|
UpdatingCache,
|
||||||
|
}
|
||||||
|
|
||||||
export type IndexedDocument = {
|
export type IndexedDocument = {
|
||||||
path: string
|
path: string
|
||||||
basename: string
|
basename: string
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
OmnisearchVaultModal,
|
OmnisearchVaultModal,
|
||||||
} from './components/modals'
|
} from './components/modals'
|
||||||
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
|
||||||
import { eventBus, EventNames } from './globals'
|
import { eventBus, EventNames, IndexingStep } from './globals'
|
||||||
import { registerAPI } from '@vanakat/plugin-api'
|
import { registerAPI } from '@vanakat/plugin-api'
|
||||||
import api from './tools/api'
|
import api from './tools/api'
|
||||||
import { isFilePlaintext, wait } from './tools/utils'
|
import { isFilePlaintext, wait } from './tools/utils'
|
||||||
@@ -114,6 +114,7 @@ async function populateIndex(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load plaintext files
|
// Load plaintext files
|
||||||
|
SearchEngine.indexingStep.set(IndexingStep.ReadingNotes)
|
||||||
console.log('Omnisearch - Reading notes')
|
console.log('Omnisearch - Reading notes')
|
||||||
const plainTextFiles = await FileLoader.getPlainTextFiles()
|
const plainTextFiles = await FileLoader.getPlainTextFiles()
|
||||||
let allFiles = [...plainTextFiles]
|
let allFiles = [...plainTextFiles]
|
||||||
@@ -125,6 +126,7 @@ async function populateIndex(): Promise<void> {
|
|||||||
|
|
||||||
// Load PDFs
|
// Load PDFs
|
||||||
if (settings.PDFIndexing) {
|
if (settings.PDFIndexing) {
|
||||||
|
SearchEngine.indexingStep.set(IndexingStep.ReadingPDFs)
|
||||||
console.log('Omnisearch - Reading PDFs')
|
console.log('Omnisearch - Reading PDFs')
|
||||||
const pdfDocuments = await FileLoader.getPDFAsDocuments()
|
const pdfDocuments = await FileLoader.getPDFAsDocuments()
|
||||||
// iOS: since there's no cache, just index the documents
|
// iOS: since there's no cache, just index the documents
|
||||||
@@ -138,6 +140,7 @@ async function populateIndex(): Promise<void> {
|
|||||||
|
|
||||||
// Load Images
|
// Load Images
|
||||||
if (settings.imagesIndexing) {
|
if (settings.imagesIndexing) {
|
||||||
|
SearchEngine.indexingStep.set(IndexingStep.ReadingImages)
|
||||||
console.log('Omnisearch - Reading Images')
|
console.log('Omnisearch - Reading Images')
|
||||||
const imagesDocuments = await FileLoader.getImagesAsDocuments()
|
const imagesDocuments = await FileLoader.getImagesAsDocuments()
|
||||||
// iOS: since there's no cache, just index the documents
|
// iOS: since there's no cache, just index the documents
|
||||||
@@ -154,6 +157,7 @@ async function populateIndex(): Promise<void> {
|
|||||||
|
|
||||||
// Other platforms: make a diff of what's to add/update/delete
|
// Other platforms: make a diff of what's to add/update/delete
|
||||||
if (!Platform.isIosApp) {
|
if (!Platform.isIosApp) {
|
||||||
|
SearchEngine.indexingStep.set(IndexingStep.UpdatingCache)
|
||||||
console.log('Omnisearch - Checking index cache diff...')
|
console.log('Omnisearch - Checking index cache diff...')
|
||||||
// Check which documents need to be removed/added/updated
|
// Check which documents need to be removed/added/updated
|
||||||
const diffDocs = await cacheManager.getDiffDocuments(allFiles)
|
const diffDocs = await cacheManager.getDiffDocuments(allFiles)
|
||||||
@@ -184,7 +188,7 @@ async function populateIndex(): Promise<void> {
|
|||||||
|
|
||||||
// Load PDFs into the main search engine, and write cache
|
// Load PDFs into the main search engine, and write cache
|
||||||
// SearchEngine.loadTmpDataIntoMain()
|
// SearchEngine.loadTmpDataIntoMain()
|
||||||
SearchEngine.isIndexing.set(false)
|
SearchEngine.indexingStep.set(IndexingStep.Done)
|
||||||
|
|
||||||
if (!Platform.isIosApp && needToUpdateCache) {
|
if (!Platform.isIosApp && needToUpdateCache) {
|
||||||
console.log('Omnisearch - Writing cache...')
|
console.log('Omnisearch - Writing cache...')
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
type ResultNote,
|
type ResultNote,
|
||||||
type SearchMatch,
|
type SearchMatch,
|
||||||
SPACE_OR_PUNCTUATION,
|
SPACE_OR_PUNCTUATION,
|
||||||
|
IndexingStep,
|
||||||
} from '../globals'
|
} from '../globals'
|
||||||
import {
|
import {
|
||||||
removeDiacritics,
|
removeDiacritics,
|
||||||
@@ -53,7 +54,7 @@ export const minisearchOptions: Options<IndexedDocument> = {
|
|||||||
|
|
||||||
export class SearchEngine {
|
export class SearchEngine {
|
||||||
private static engine?: SearchEngine
|
private static engine?: SearchEngine
|
||||||
public static isIndexing = writable(true)
|
public static indexingStep = writable(IndexingStep.LoadingCache)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main singleton SearchEngine instance.
|
* The main singleton SearchEngine instance.
|
||||||
|
|||||||
Reference in New Issue
Block a user