From 71826148fd6799f7b8fc4aebf450e9eb9fa47146 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 13 Mar 2023 15:15:47 +0800 Subject: [PATCH] Add type to the highlight in the elasticsearch and three types are HIGHLIGHTS, REDACTION and NOTE --- packages/api/src/elastic/types.ts | 7 ++++ .../db/elastic_migrations/index_settings.json | 4 +++ packages/db/migrate.ts | 33 ------------------- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/packages/api/src/elastic/types.ts b/packages/api/src/elastic/types.ts index 8191115ac..513b425c7 100644 --- a/packages/api/src/elastic/types.ts +++ b/packages/api/src/elastic/types.ts @@ -71,6 +71,12 @@ export enum ArticleSavingRequestStatus { Deleted = 'DELETED', } +export enum HighlightType { + Highlight = 'HIGHLIGHT', + Redaction = 'REDACTION', // allowing people to remove text from the page + Note = 'NOTE', // allowing people to add a note at the document level +} + export interface Label { id: string name: string @@ -94,6 +100,7 @@ export interface Highlight { labels?: Label[] highlightPositionPercent?: number | null highlightPositionAnchorIndex?: number | null + type: HighlightType html?: string | null } diff --git a/packages/db/elastic_migrations/index_settings.json b/packages/db/elastic_migrations/index_settings.json index 1d9c977e1..6b14fd5ce 100644 --- a/packages/db/elastic_migrations/index_settings.json +++ b/packages/db/elastic_migrations/index_settings.json @@ -84,6 +84,10 @@ "userId": { "type": "keyword" }, + "type": { + "type": "keyword", + "null_value": "HIGHLIGHT" + }, "quote": { "type": "text", "analyzer": "strip_html_analyzer" diff --git a/packages/db/migrate.ts b/packages/db/migrate.ts index 8a4386940..ef17fe997 100755 --- a/packages/db/migrate.ts +++ b/packages/db/migrate.ts @@ -148,41 +148,8 @@ const elasticMigration = esClient.indices log('Elastic index mappings updated.') }) }) - .then(() => { - log('Adding default state to pages in elastic...') - return esClient - .update_by_query({ - index: INDEX_ALIAS, - requests_per_second: 250, - scroll_size: 500, - timeout: '30m', - body: { - script: { - source: 'ctx._source.state = params.state', - lang: 'painless', - params: { - state: 'SUCCEEDED', - }, - }, - query: { - bool: { - must_not: [ - { - exists: { - field: 'state', - }, - }, - ], - }, - }, - }, - }) - .then(() => log('Default state added.')) - }) .catch((error) => { log(`${chalk.red('Elastic migration failed: ')}${error.message}`, chalk.red) - const { appliedMigrations } = error - logAppliedMigrations(appliedMigrations) process.exit(1) })