Skip to content

Commit

Permalink
Add button for incremental semantic search index update (fixes #551)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Dec 28, 2024
1 parent 1222954 commit 25ed056
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 26 deletions.
8 changes: 6 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,9 @@
"Nobody": "Nobody",
"User group": "User group",
"User Information": "User Information",
"Tree Information": "Tree Information"
}
"Tree Information": "Tree Information",
"Regenerate semantic search index": "Regenerate semantic search index",
"Settings": "Settings",
"Pending": "Pending",
"Started": "Started"
}
12 changes: 11 additions & 1 deletion src/components/GrampsjsProgressIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,10 +88,17 @@ export class GrampsjsProgressIndicator extends LitElement {
return html`
<mwc-circular-progress
indeterminate
id="progress-indeterminate"
style="--mdc-theme-primary: rgba(0, 0, 0, 0.5);"
density="${this._getDensity()}"
>
</mwc-circular-progress>
${this.infoMessage
? html` <grampsjs-tooltip
for="progress-indeterminate"
content="${this.infoMessage}"
></grampsjs-tooltip>`
: ''}
`
}

Expand Down
6 changes: 6 additions & 0 deletions src/components/GrampsjsTaskProgressIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? ''}
Expand Down
71 changes: 48 additions & 23 deletions src/views/GrampsjsViewAdminSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
></grampsjs-task-progress-indicator>
Expand All @@ -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.'
)}
</p>
<mwc-button
outlined
?disabled=${this._buttonUpdateSearchSemanticDisabled}
@click="${() => this._updateSearch(true)}"
@keydown="${clickKeyHandler}"
>${this._('Update semantic search index')}</mwc-button
>
<grampsjs-task-progress-indicator
class="button"
id="progress-update-search-semantic"
taskName="searchReindexFullSemantic"
size="20"
pollInterval="0.2"
@task:complete="${this._handleSuccessUpdateSearch}"
></grampsjs-task-progress-indicator>
<p>
<mwc-button
outlined
?disabled=${this._buttonUpdateSearchSemanticDisabled}
@click="${() => this._updateSearch(true)}"
@keydown="${clickKeyHandler}"
>${this._('Regenerate semantic search index')}</mwc-button
>
<grampsjs-task-progress-indicator
class="button"
id="progress-update-search-semantic"
taskName="searchReindexFullSemantic"
size="20"
pollInterval="1.0"
@task:complete="${this._handleSuccessUpdateSearch}"
></grampsjs-task-progress-indicator>
</p>
<p>
<mwc-button
outlined
?disabled=${this._buttonUpdateSearchSemanticDisabled}
@click="${() => this._updateSearch(true, true)}"
@keydown="${clickKeyHandler}"
>${this._('Update semantic search index')}</mwc-button
>
<grampsjs-task-progress-indicator
class="button"
id="progress-update-search-semantic-incremental"
taskName="searchReindexIncrementalSemantic"
size="20"
pollInterval="1.0"
@task:complete="${this._handleSuccessUpdateSearch}"
></grampsjs-task-progress-indicator>
</p>
`
: ''}
<h3>${this._('Check and Repair Database')}</h3>
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 25ed056

Please sign in to comment.