From 25ed056634834e05cb6f38d2e29b6254a18e897f Mon Sep 17 00:00:00 2001 From: David Straub Date: Sat, 28 Dec 2024 17:52:39 +0100 Subject: [PATCH] Add button for incremental semantic search index update (fixes #551) --- lang/en.json | 8 ++- src/components/GrampsjsProgressIndicator.js | 12 +++- .../GrampsjsTaskProgressIndicator.js | 6 ++ src/views/GrampsjsViewAdminSettings.js | 71 +++++++++++++------ 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/lang/en.json b/lang/en.json index c5977963..3c8bce1e 100644 --- a/lang/en.json +++ b/lang/en.json @@ -187,5 +187,9 @@ "Nobody": "Nobody", "User group": "User group", "User Information": "User Information", - "Tree Information": "Tree Information" -} \ No newline at end of file + "Tree Information": "Tree Information", + "Regenerate semantic search index": "Regenerate semantic search index", + "Settings": "Settings", + "Pending": "Pending", + "Started": "Started" +} diff --git a/src/components/GrampsjsProgressIndicator.js b/src/components/GrampsjsProgressIndicator.js index 539aba77..3362fed6 100644 --- a/src/components/GrampsjsProgressIndicator.js +++ b/src/components/GrampsjsProgressIndicator.js @@ -5,8 +5,11 @@ import '@material/mwc-icon' import {sharedStyles} from '../SharedStyles.js' import {fireEvent} from '../util.js' +import {GrampsjsTranslateMixin} from '../mixins/GrampsjsTranslateMixin.js' -export class GrampsjsProgressIndicator extends LitElement { +export class GrampsjsProgressIndicator extends GrampsjsTranslateMixin( + LitElement +) { static get styles() { return [ sharedStyles, @@ -85,10 +88,17 @@ export class GrampsjsProgressIndicator extends LitElement { return html` + ${this.infoMessage + ? html` ` + : ''} ` } diff --git a/src/components/GrampsjsTaskProgressIndicator.js b/src/components/GrampsjsTaskProgressIndicator.js index 6265a1b5..4fca4c6c 100644 --- a/src/components/GrampsjsTaskProgressIndicator.js +++ b/src/components/GrampsjsTaskProgressIndicator.js @@ -55,6 +55,12 @@ export class GrampsjsTaskProgressIndicator extends GrampsjsProgressIndicator { this.setComplete() } else if (status.state === 'FAILURE' || status.state === 'REVOKED') { this.setError() + } else if (status.state === 'PENDING') { + this.progress = status.result_object?.progress ?? -1 + this.infoMessage = this._('Pending') + } else if (status.state === 'STARTED') { + this.progress = status.result_object?.progress ?? -1 + this.infoMessage = this._('Started') } else if (status.state === 'PROGRESS') { this.progress = status.result_object?.progress ?? -1 this.infoMessage = `${status.result_object?.title ?? ''} diff --git a/src/views/GrampsjsViewAdminSettings.js b/src/views/GrampsjsViewAdminSettings.js index da213930..ad4173f1 100644 --- a/src/views/GrampsjsViewAdminSettings.js +++ b/src/views/GrampsjsViewAdminSettings.js @@ -136,7 +136,7 @@ export class GrampsjsViewAdminSettings extends GrampsjsView { id="progress-update-search" taskName="searchReindexFull" size="20" - pollInterval="0.2" + pollInterval="0.5" @task:complete="${this._handleSuccessUpdateSearch}" > @@ -151,21 +151,40 @@ export class GrampsjsViewAdminSettings extends GrampsjsView { 'Updating the semantic search index requires substantial time and computational resources. Run this operation only when necessary.' )}

- ${this._('Update semantic search index')} - +

+ ${this._('Regenerate semantic search index')} + +

+

+ ${this._('Update semantic search index')} + +

` : ''}

${this._('Check and Repair Database')}

@@ -285,16 +304,22 @@ export class GrampsjsViewAdminSettings extends GrampsjsView { } } - async _updateSearch(semantic = false) { - const id = semantic - ? 'progress-update-search-semantic' - : 'progress-update-search' + async _updateSearch(semantic = false, incremental = false) { + let id + if (semantic) { + id = incremental + ? 'progress-update-search-semantic-incremental' + : 'progress-update-search-semantic' + } else { + id = 'progress-update-search' + } const prog = this.renderRoot.querySelector(`#${id}`) prog.reset() prog.open = true - const url = semantic - ? '/api/search/index/?full=1&semantic=1' - : '/api/search/index/?full=1' + const params = new URLSearchParams() + if (!incremental) params.append('full', '1') + if (semantic) params.append('semantic', '1') + const url = `/api/search/index/?${params.toString()}` if (semantic) { this._buttonUpdateSearchSemanticDisabled = true } else {