@backstage/plugin-search-backend-module-pg 0.3.5-next.0 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +28 -0
- package/config.d.ts +62 -0
- package/dist/index.cjs.js +45 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +86 -36
- package/package.json +14 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @backstage/plugin-search-backend-module-pg
|
|
2
2
|
|
|
3
|
+
## 0.3.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 423e3d8e95: **DEPRECATED**: `PgSearchEngine` static `from` has been deprecated and will be removed in a future release. Use static `fromConfig` method to instantiate.
|
|
8
|
+
|
|
9
|
+
Added support for highlighting matched terms in search result data
|
|
10
|
+
|
|
11
|
+
- 679b32172e: Updated dependency `knex` to `^2.0.0`.
|
|
12
|
+
- 886e99b8e7: Now imports `SearchEngine` interface from `@backstage/plugin-search-common` instead of `@backstage/plugin-search-backend-node`
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- @backstage/backend-common@0.14.1
|
|
15
|
+
- @backstage/plugin-search-backend-node@1.0.0
|
|
16
|
+
- @backstage/plugin-search-common@1.0.0
|
|
17
|
+
|
|
18
|
+
## 0.3.5-next.2
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 423e3d8e95: **DEPRECATED**: `PgSearchEngine` static `from` has been deprecated and will be removed in a future release. Use static `fromConfig` method to instantiate.
|
|
23
|
+
|
|
24
|
+
Added support for highlighting matched terms in search result data
|
|
25
|
+
|
|
26
|
+
- 679b32172e: Updated dependency `knex` to `^2.0.0`.
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @backstage/backend-common@0.14.1-next.2
|
|
29
|
+
|
|
30
|
+
## 0.3.5-next.1
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies
|
|
35
|
+
- @backstage/backend-common@0.14.1-next.1
|
|
36
|
+
- @backstage/plugin-search-backend-node@0.6.3-next.1
|
|
37
|
+
- @backstage/plugin-search-common@0.3.6-next.0
|
|
38
|
+
|
|
3
39
|
## 0.3.5-next.0
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -14,3 +14,31 @@ other plugins.
|
|
|
14
14
|
|
|
15
15
|
See [Backstage documentation](https://backstage.io/docs/features/search/search-engines#postgres)
|
|
16
16
|
for details on how to setup Postgres based search for your Backstage instance.
|
|
17
|
+
|
|
18
|
+
## Optional Configuration
|
|
19
|
+
|
|
20
|
+
The following is an example of the optional configuration that can be applied when using Postgres as the search backend. Currently this is mostly for just the highlight feature:
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
search:
|
|
24
|
+
pg:
|
|
25
|
+
highlightOptions:
|
|
26
|
+
useHighlight: true # Used to enable to disable the highlight feature. The default value is true
|
|
27
|
+
maxWord: 35 # Used to set the longest headlines to output. The default value is 35.
|
|
28
|
+
minWord: 15 # Used to set the shortest headlines to output. The default value is 15.
|
|
29
|
+
shortWord: 3 # Words of this length or less will be dropped at the start and end of a headline, unless they are query terms. The default value of three (3) eliminates common English articles.
|
|
30
|
+
highlightAll: false # If true the whole document will be used as the headline, ignoring the preceding three parameters. The default is false.
|
|
31
|
+
maxFragments: 0 # Maximum number of text fragments to display. The default value of zero selects a non-fragment-based headline generation method. A value greater than zero selects fragment-based headline generation (see the linked documentation above for more details).
|
|
32
|
+
fragmentDelimiter: ' ... ' # Delimiter string used to concatenate fragments. Defaults to " ... ".
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Note:** the highlight search term feature uses `ts_headline` which has been known to potentially impact performance. You only need this minimal config to disable it should you have issues:
|
|
36
|
+
|
|
37
|
+
```yaml
|
|
38
|
+
search:
|
|
39
|
+
pg:
|
|
40
|
+
highlightOptions:
|
|
41
|
+
useHighlight: false
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The Postgres documentation on [Highlighting Results](https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-HEADLINE) has more details.
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2021 The Backstage Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface Config {
|
|
18
|
+
/** Configuration options for the search plugin */
|
|
19
|
+
search?: {
|
|
20
|
+
/**
|
|
21
|
+
* Options for PG
|
|
22
|
+
*/
|
|
23
|
+
pg?: {
|
|
24
|
+
/**
|
|
25
|
+
* Options for configuring highlight settings
|
|
26
|
+
* See https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-HEADLINE
|
|
27
|
+
*/
|
|
28
|
+
highlightOptions?: {
|
|
29
|
+
/**
|
|
30
|
+
* Used to enable to disable the highlight feature. The default value is true
|
|
31
|
+
*/
|
|
32
|
+
useHighlight?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Used to set the longest headlines to output. The default value is 35.
|
|
35
|
+
*/
|
|
36
|
+
maxWords?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Used to set the shortest headlines to output. The default value is 15.
|
|
39
|
+
*/
|
|
40
|
+
minWords?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Words of this length or less will be dropped at the start and end of a headline, unless they are query terms.
|
|
43
|
+
* The default value of three (3) eliminates common English articles.
|
|
44
|
+
*/
|
|
45
|
+
shortWord?: number;
|
|
46
|
+
/**
|
|
47
|
+
* If true the whole document will be used as the headline, ignoring the preceding three parameters. The default is false.
|
|
48
|
+
*/
|
|
49
|
+
highlightAll?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Maximum number of text fragments to display. The default value of zero selects a non-fragment-based headline generation method.
|
|
52
|
+
* A value greater than zero selects fragment-based headline generation (see the linked documentation above for more details).
|
|
53
|
+
*/
|
|
54
|
+
maxFragments?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Delimiter string used to concatenate fragments. Defaults to " ... ".
|
|
57
|
+
*/
|
|
58
|
+
fragmentDelimiter?: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var backendCommon = require('@backstage/backend-common');
|
|
6
6
|
var pluginSearchBackendNode = require('@backstage/plugin-search-backend-node');
|
|
7
|
+
var uuid = require('uuid');
|
|
7
8
|
|
|
8
9
|
async function queryPostgresMajorVersion(knex) {
|
|
9
10
|
if (knex.client.config.client !== "pg") {
|
|
@@ -62,7 +63,8 @@ class DatabaseDocumentStore {
|
|
|
62
63
|
document
|
|
63
64
|
})));
|
|
64
65
|
}
|
|
65
|
-
async query(tx,
|
|
66
|
+
async query(tx, searchQuery) {
|
|
67
|
+
const { types, pgTerm, fields, offset, limit, options } = searchQuery;
|
|
66
68
|
const query = tx("documents");
|
|
67
69
|
if (pgTerm) {
|
|
68
70
|
query.from(tx.raw("documents, to_tsquery('english', ?) query", pgTerm)).whereRaw("query @@ body");
|
|
@@ -81,7 +83,10 @@ class DatabaseDocumentStore {
|
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
query.select("type", "document");
|
|
84
|
-
if (pgTerm) {
|
|
86
|
+
if (pgTerm && options.useHighlight) {
|
|
87
|
+
const headlineOptions = `MaxWords=${options.maxWords}, MinWords=${options.minWords}, ShortWord=${options.shortWord}, HighlightAll=${options.highlightAll}, MaxFragments=${options.maxFragments}, FragmentDelimiter=${options.fragmentDelimiter}, StartSel=${options.preTag}, StopSel=${options.postTag}`;
|
|
88
|
+
query.select(tx.raw('ts_rank_cd(body, query) AS "rank"')).select(tx.raw(`ts_headline('english', document, query, '${headlineOptions}') as "highlight"`)).orderBy("rank", "desc");
|
|
89
|
+
} else if (pgTerm && !options.useHighlight) {
|
|
85
90
|
query.select(tx.raw('ts_rank_cd(body, query) AS "rank"')).orderBy("rank", "desc");
|
|
86
91
|
} else {
|
|
87
92
|
query.select(tx.raw("1 as rank"));
|
|
@@ -125,16 +130,34 @@ class PgSearchEngineIndexer extends pluginSearchBackendNode.BatchSearchEngineInd
|
|
|
125
130
|
}
|
|
126
131
|
|
|
127
132
|
class PgSearchEngine {
|
|
128
|
-
constructor(databaseStore) {
|
|
133
|
+
constructor(databaseStore, config) {
|
|
129
134
|
this.databaseStore = databaseStore;
|
|
135
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
136
|
+
const uuidTag = uuid.v4();
|
|
137
|
+
const highlightConfig = config.getOptionalConfig("search.pg.highlightOptions");
|
|
138
|
+
const highlightOptions = {
|
|
139
|
+
preTag: `<${uuidTag}>`,
|
|
140
|
+
postTag: `</${uuidTag}>`,
|
|
141
|
+
useHighlight: (_a = highlightConfig == null ? void 0 : highlightConfig.getOptionalBoolean("useHighlight")) != null ? _a : true,
|
|
142
|
+
maxWords: (_b = highlightConfig == null ? void 0 : highlightConfig.getOptionalNumber("maxWords")) != null ? _b : 35,
|
|
143
|
+
minWords: (_c = highlightConfig == null ? void 0 : highlightConfig.getOptionalNumber("minWords")) != null ? _c : 15,
|
|
144
|
+
shortWord: (_d = highlightConfig == null ? void 0 : highlightConfig.getOptionalNumber("shortWord")) != null ? _d : 3,
|
|
145
|
+
highlightAll: (_e = highlightConfig == null ? void 0 : highlightConfig.getOptionalBoolean("highlightAll")) != null ? _e : false,
|
|
146
|
+
maxFragments: (_f = highlightConfig == null ? void 0 : highlightConfig.getOptionalNumber("maxFragments")) != null ? _f : 0,
|
|
147
|
+
fragmentDelimiter: (_g = highlightConfig == null ? void 0 : highlightConfig.getOptionalString("fragmentDelimiter")) != null ? _g : " ... "
|
|
148
|
+
};
|
|
149
|
+
this.highlightOptions = highlightOptions;
|
|
130
150
|
}
|
|
131
151
|
static async from(options) {
|
|
132
|
-
return new PgSearchEngine(await DatabaseDocumentStore.create(await options.database.getClient()));
|
|
152
|
+
return new PgSearchEngine(await DatabaseDocumentStore.create(await options.database.getClient()), options.config);
|
|
153
|
+
}
|
|
154
|
+
static async fromConfig(config, options) {
|
|
155
|
+
return new PgSearchEngine(await DatabaseDocumentStore.create(await options.database.getClient()), config);
|
|
133
156
|
}
|
|
134
157
|
static async supported(database) {
|
|
135
158
|
return await DatabaseDocumentStore.supported(await database.getClient());
|
|
136
159
|
}
|
|
137
|
-
translator(query) {
|
|
160
|
+
translator(query, options) {
|
|
138
161
|
const pageSize = 25;
|
|
139
162
|
const { page } = decodePageCursor(query.pageCursor);
|
|
140
163
|
const offset = page * pageSize;
|
|
@@ -145,7 +168,8 @@ class PgSearchEngine {
|
|
|
145
168
|
fields: query.filters,
|
|
146
169
|
types: query.types,
|
|
147
170
|
offset,
|
|
148
|
-
limit
|
|
171
|
+
limit,
|
|
172
|
+
options: options.highlightOptions
|
|
149
173
|
},
|
|
150
174
|
pageSize
|
|
151
175
|
};
|
|
@@ -161,7 +185,9 @@ class PgSearchEngine {
|
|
|
161
185
|
});
|
|
162
186
|
}
|
|
163
187
|
async query(query) {
|
|
164
|
-
const { pgQuery, pageSize } = this.translator(query
|
|
188
|
+
const { pgQuery, pageSize } = this.translator(query, {
|
|
189
|
+
highlightOptions: this.highlightOptions
|
|
190
|
+
});
|
|
165
191
|
const rows = await this.databaseStore.transaction(async (tx) => this.databaseStore.query(tx, pgQuery));
|
|
166
192
|
const { page } = decodePageCursor(query.pageCursor);
|
|
167
193
|
const hasNextPage = rows.length > pageSize;
|
|
@@ -169,10 +195,20 @@ class PgSearchEngine {
|
|
|
169
195
|
const pageRows = rows.slice(0, pageSize);
|
|
170
196
|
const nextPageCursor = hasNextPage ? encodePageCursor({ page: page + 1 }) : void 0;
|
|
171
197
|
const previousPageCursor = hasPreviousPage ? encodePageCursor({ page: page - 1 }) : void 0;
|
|
172
|
-
const results = pageRows.map(({ type, document }, index) => ({
|
|
198
|
+
const results = pageRows.map(({ type, document, highlight }, index) => ({
|
|
173
199
|
type,
|
|
174
200
|
document,
|
|
175
|
-
rank: page * pageSize + index + 1
|
|
201
|
+
rank: page * pageSize + index + 1,
|
|
202
|
+
highlight: {
|
|
203
|
+
preTag: pgQuery.options.preTag,
|
|
204
|
+
postTag: pgQuery.options.postTag,
|
|
205
|
+
fields: highlight ? {
|
|
206
|
+
text: highlight.text,
|
|
207
|
+
title: highlight.title,
|
|
208
|
+
location: highlight.location,
|
|
209
|
+
path: ""
|
|
210
|
+
} : {}
|
|
211
|
+
}
|
|
176
212
|
}));
|
|
177
213
|
return { results, nextPageCursor, previousPageCursor };
|
|
178
214
|
}
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/database/util.ts","../src/database/DatabaseDocumentStore.ts","../src/PgSearchEngine/PgSearchEngineIndexer.ts","../src/PgSearchEngine/PgSearchEngine.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Knex } from 'knex';\n\nexport async function queryPostgresMajorVersion(knex: Knex): Promise<number> {\n if (knex.client.config.client !== 'pg') {\n throw new Error(\"Can't resolve version, not a postgres database\");\n }\n\n const { rows } = await knex.raw('SHOW server_version_num');\n const [result] = rows;\n const version = +result.server_version_num;\n const majorVersion = Math.floor(version / 10000);\n return majorVersion;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { resolvePackagePath } from '@backstage/backend-common';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Knex } from 'knex';\nimport {\n DatabaseStore,\n DocumentResultRow,\n PgSearchQuery,\n RawDocumentRow,\n} from './types';\nimport { queryPostgresMajorVersion } from './util';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-search-backend-module-pg',\n 'migrations',\n);\n\nexport class DatabaseDocumentStore implements DatabaseStore {\n static async create(knex: Knex): Promise<DatabaseDocumentStore> {\n try {\n const majorVersion = await queryPostgresMajorVersion(knex);\n\n if (majorVersion < 12) {\n // We are using some features (like generated columns) that aren't\n // available in older postgres versions.\n throw new Error(\n `The PgSearchEngine requires at least postgres version 12 (but is running on ${majorVersion})`,\n );\n }\n } catch {\n // Actually both mysql and sqlite have a full text search, too. We could\n // implement them separately or add them here.\n throw new Error(\n 'The PgSearchEngine is only supported when using a postgres database (>=12.x)',\n );\n }\n\n await knex.migrate.latest({\n directory: migrationsDir,\n });\n return new DatabaseDocumentStore(knex);\n }\n\n static async supported(knex: Knex): Promise<boolean> {\n try {\n const majorVersion = await queryPostgresMajorVersion(knex);\n\n return majorVersion >= 12;\n } catch {\n return false;\n }\n }\n\n constructor(private readonly db: Knex) {}\n\n async transaction<T>(fn: (tx: Knex.Transaction) => Promise<T>): Promise<T> {\n return await this.db.transaction(fn);\n }\n\n async getTransaction(): Promise<Knex.Transaction> {\n return this.db.transaction();\n }\n\n async prepareInsert(tx: Knex.Transaction): Promise<void> {\n // We create a temporary table to collect the hashes of the documents that\n // we expect to be in the documents table at the end. The table is deleted\n // at the end of the transaction.\n // The hash makes sure that we generate a new row for every change.\n await tx.raw(\n 'CREATE TEMP TABLE documents_to_insert (' +\n 'type text NOT NULL, ' +\n 'document jsonb NOT NULL, ' +\n // Generating the hash requires a trick, as the text to bytea\n // conversation runs into errors in case the text contains a backslash.\n // Therefore we have to escape them.\n \"hash bytea NOT NULL GENERATED ALWAYS AS (sha256(replace(document::text || type, '\\\\', '\\\\\\\\')::bytea)) STORED\" +\n ') ON COMMIT DROP',\n );\n }\n\n async completeInsert(tx: Knex.Transaction, type: string): Promise<void> {\n // Copy all new rows into the documents table\n await tx\n .insert(\n tx<RawDocumentRow>('documents_to_insert').select(\n 'type',\n 'document',\n 'hash',\n ),\n )\n .into(tx.raw('documents (type, document, hash)'))\n .onConflict('hash')\n .ignore();\n\n // Delete all documents that we don't expect (deleted and changed)\n await tx<RawDocumentRow>('documents')\n .where({ type })\n .whereNotIn(\n 'hash',\n tx<RawDocumentRow>('documents_to_insert').select('hash'),\n )\n .delete();\n }\n\n async insertDocuments(\n tx: Knex.Transaction,\n type: string,\n documents: IndexableDocument[],\n ): Promise<void> {\n // Insert all documents into the temporary table to process them later\n await tx<DocumentResultRow>('documents_to_insert').insert(\n documents.map(document => ({\n type,\n document,\n })),\n );\n }\n\n async query(\n tx: Knex.Transaction,\n { types, pgTerm, fields, offset, limit }: PgSearchQuery,\n ): Promise<DocumentResultRow[]> {\n // Builds a query like:\n // SELECT ts_rank_cd(body, query) AS rank, type, document\n // FROM documents, to_tsquery('english', 'consent') query\n // WHERE query @@ body AND (document @> '{\"kind\": \"API\"}')\n // ORDER BY rank DESC\n // LIMIT 10;\n const query = tx<DocumentResultRow>('documents');\n\n if (pgTerm) {\n query\n .from(tx.raw(\"documents, to_tsquery('english', ?) query\", pgTerm))\n .whereRaw('query @@ body');\n } else {\n query.from('documents');\n }\n\n if (types) {\n query.whereIn('type', types);\n }\n\n if (fields) {\n Object.keys(fields).forEach(key => {\n const value = fields[key];\n const valueArray = Array.isArray(value) ? value : [value];\n const valueCompare = valueArray\n .map(v => ({ [key]: v }))\n .map(v => JSON.stringify(v));\n query.whereRaw(\n `(${valueCompare.map(() => 'document @> ?').join(' OR ')})`,\n valueCompare,\n );\n });\n }\n\n query.select('type', 'document');\n\n if (pgTerm) {\n query\n .select(tx.raw('ts_rank_cd(body, query) AS \"rank\"'))\n .orderBy('rank', 'desc');\n } else {\n query.select(tx.raw('1 as rank'));\n }\n\n return await query.offset(offset).limit(limit);\n }\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BatchSearchEngineIndexer } from '@backstage/plugin-search-backend-node';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Knex } from 'knex';\nimport { DatabaseStore } from '../database';\n\nexport type PgSearchEngineIndexerOptions = {\n batchSize: number;\n type: string;\n databaseStore: DatabaseStore;\n};\n\nexport class PgSearchEngineIndexer extends BatchSearchEngineIndexer {\n private store: DatabaseStore;\n private type: string;\n private tx: Knex.Transaction | undefined;\n\n constructor(options: PgSearchEngineIndexerOptions) {\n super({ batchSize: options.batchSize });\n this.store = options.databaseStore;\n this.type = options.type;\n }\n\n async initialize(): Promise<void> {\n this.tx = await this.store.getTransaction();\n try {\n await this.store.prepareInsert(this.tx);\n } catch (e) {\n // In case of error, rollback the transaction and re-throw the error so\n // that the stream can be closed and destroyed properly.\n this.tx.rollback(e);\n throw e;\n }\n }\n\n async index(documents: IndexableDocument[]): Promise<void> {\n try {\n await this.store.insertDocuments(this.tx!, this.type, documents);\n } catch (e) {\n // In case of error, rollback the transaction and re-throw the error so\n // that the stream can be closed and destroyed properly.\n this.tx!.rollback(e);\n throw e;\n }\n }\n\n async finalize(): Promise<void> {\n // Attempt to complete and commit the transaction.\n try {\n await this.store.completeInsert(this.tx!, this.type);\n this.tx!.commit();\n } catch (e) {\n // Otherwise, rollback the transaction and re-throw the error so that the\n // stream can be closed and destroyed properly.\n this.tx!.rollback!(e);\n throw e;\n }\n }\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { PluginDatabaseManager } from '@backstage/backend-common';\nimport { SearchEngine } from '@backstage/plugin-search-backend-node';\nimport {\n SearchQuery,\n IndexableResultSet,\n IndexableResult,\n} from '@backstage/plugin-search-common';\nimport { PgSearchEngineIndexer } from './PgSearchEngineIndexer';\nimport {\n DatabaseDocumentStore,\n DatabaseStore,\n PgSearchQuery,\n} from '../database';\n\nexport type ConcretePgSearchQuery = {\n pgQuery: PgSearchQuery;\n pageSize: number;\n};\n\nexport class PgSearchEngine implements SearchEngine {\n constructor(private readonly databaseStore: DatabaseStore) {}\n\n static async from(options: {\n database: PluginDatabaseManager;\n }): Promise<PgSearchEngine> {\n return new PgSearchEngine(\n await DatabaseDocumentStore.create(await options.database.getClient()),\n );\n }\n\n static async supported(database: PluginDatabaseManager): Promise<boolean> {\n return await DatabaseDocumentStore.supported(await database.getClient());\n }\n\n translator(query: SearchQuery): ConcretePgSearchQuery {\n const pageSize = 25;\n const { page } = decodePageCursor(query.pageCursor);\n const offset = page * pageSize;\n // We request more result to know whether there is another page\n const limit = pageSize + 1;\n\n return {\n pgQuery: {\n pgTerm: query.term\n .split(/\\s/)\n .map(p => p.replace(/[\\0()|&:*!]/g, '').trim())\n .filter(p => p !== '')\n .map(p => `(${JSON.stringify(p)} | ${JSON.stringify(p)}:*)`)\n .join('&'),\n fields: query.filters as Record<string, string | string[]>,\n types: query.types,\n offset,\n limit,\n },\n pageSize,\n };\n }\n\n setTranslator(\n translator: (query: SearchQuery) => ConcretePgSearchQuery,\n ): void {\n this.translator = translator;\n }\n\n async getIndexer(type: string) {\n return new PgSearchEngineIndexer({\n batchSize: 1000,\n type,\n databaseStore: this.databaseStore,\n });\n }\n\n async query(query: SearchQuery): Promise<IndexableResultSet> {\n const { pgQuery, pageSize } = this.translator(query);\n\n const rows = await this.databaseStore.transaction(async tx =>\n this.databaseStore.query(tx, pgQuery),\n );\n\n // We requested one result more than the page size to know whether there is\n // another page.\n const { page } = decodePageCursor(query.pageCursor);\n const hasNextPage = rows.length > pageSize;\n const hasPreviousPage = page > 0;\n const pageRows = rows.slice(0, pageSize);\n const nextPageCursor = hasNextPage\n ? encodePageCursor({ page: page + 1 })\n : undefined;\n const previousPageCursor = hasPreviousPage\n ? encodePageCursor({ page: page - 1 })\n : undefined;\n\n const results = pageRows.map(\n ({ type, document }, index): IndexableResult => ({\n type,\n document,\n rank: page * pageSize + index + 1,\n }),\n );\n\n return { results, nextPageCursor, previousPageCursor };\n }\n}\n\nexport function decodePageCursor(pageCursor?: string): { page: number } {\n if (!pageCursor) {\n return { page: 0 };\n }\n\n return {\n page: Number(Buffer.from(pageCursor, 'base64').toString('utf-8')),\n };\n}\n\nexport function encodePageCursor({ page }: { page: number }): string {\n return Buffer.from(`${page}`, 'utf-8').toString('base64');\n}\n"],"names":["resolvePackagePath","BatchSearchEngineIndexer"],"mappings":";;;;;;;AAAO,eAAe,yBAAyB,CAAC,IAAI,EAAE;AACtD,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE;AAC1C,IAAI,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;AACtE,GAAG;AACH,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAC7D,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AACxB,EAAE,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC;AAC7C,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;AACjD,EAAE,OAAO,YAAY,CAAC;AACtB;;ACPA,MAAM,aAAa,GAAGA,gCAAkB,CAAC,4CAA4C,EAAE,YAAY,CAAC,CAAC;AAC9F,MAAM,qBAAqB,CAAC;AACnC,EAAE,WAAW,CAAC,EAAE,EAAE;AAClB,IAAI,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AACjB,GAAG;AACH,EAAE,aAAa,MAAM,CAAC,IAAI,EAAE;AAC5B,IAAI,IAAI;AACR,MAAM,MAAM,YAAY,GAAG,MAAM,yBAAyB,CAAC,IAAI,CAAC,CAAC;AACjE,MAAM,IAAI,YAAY,GAAG,EAAE,EAAE;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,4EAA4E,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AACxH,OAAO;AACP,KAAK,CAAC,MAAM;AACZ,MAAM,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;AACtG,KAAK;AACL,IAAI,MAAM,IAA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AE,cAAc,EAAE,kBAAkB,EAAE,CAAC;AAC3D,GAAG;AACH,CAAC;AACM,SAAS,gBAAgB,CAAC,UAAU,EAAE;AAC7C,EAAE,IAAI,CAAC,UAAU,EAAE;AACnB,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AACvB,GAAG;AACH,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACrE,GAAG,CAAC;AACJ,CAAC;AACM,SAAS,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE;AAC3C,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC5D;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/database/util.ts","../src/database/DatabaseDocumentStore.ts","../src/PgSearchEngine/PgSearchEngineIndexer.ts","../src/PgSearchEngine/PgSearchEngine.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Knex } from 'knex';\n\nexport async function queryPostgresMajorVersion(knex: Knex): Promise<number> {\n if (knex.client.config.client !== 'pg') {\n throw new Error(\"Can't resolve version, not a postgres database\");\n }\n\n const { rows } = await knex.raw('SHOW server_version_num');\n const [result] = rows;\n const version = +result.server_version_num;\n const majorVersion = Math.floor(version / 10000);\n return majorVersion;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { resolvePackagePath } from '@backstage/backend-common';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Knex } from 'knex';\nimport {\n DatabaseStore,\n DocumentResultRow,\n PgSearchQuery,\n RawDocumentRow,\n} from './types';\nimport { queryPostgresMajorVersion } from './util';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-search-backend-module-pg',\n 'migrations',\n);\n\nexport class DatabaseDocumentStore implements DatabaseStore {\n static async create(knex: Knex): Promise<DatabaseDocumentStore> {\n try {\n const majorVersion = await queryPostgresMajorVersion(knex);\n\n if (majorVersion < 12) {\n // We are using some features (like generated columns) that aren't\n // available in older postgres versions.\n throw new Error(\n `The PgSearchEngine requires at least postgres version 12 (but is running on ${majorVersion})`,\n );\n }\n } catch {\n // Actually both mysql and sqlite have a full text search, too. We could\n // implement them separately or add them here.\n throw new Error(\n 'The PgSearchEngine is only supported when using a postgres database (>=12.x)',\n );\n }\n\n await knex.migrate.latest({\n directory: migrationsDir,\n });\n return new DatabaseDocumentStore(knex);\n }\n\n static async supported(knex: Knex): Promise<boolean> {\n try {\n const majorVersion = await queryPostgresMajorVersion(knex);\n\n return majorVersion >= 12;\n } catch {\n return false;\n }\n }\n\n constructor(private readonly db: Knex) {}\n\n async transaction<T>(fn: (tx: Knex.Transaction) => Promise<T>): Promise<T> {\n return await this.db.transaction(fn);\n }\n\n async getTransaction(): Promise<Knex.Transaction> {\n return this.db.transaction();\n }\n\n async prepareInsert(tx: Knex.Transaction): Promise<void> {\n // We create a temporary table to collect the hashes of the documents that\n // we expect to be in the documents table at the end. The table is deleted\n // at the end of the transaction.\n // The hash makes sure that we generate a new row for every change.\n await tx.raw(\n 'CREATE TEMP TABLE documents_to_insert (' +\n 'type text NOT NULL, ' +\n 'document jsonb NOT NULL, ' +\n // Generating the hash requires a trick, as the text to bytea\n // conversation runs into errors in case the text contains a backslash.\n // Therefore we have to escape them.\n \"hash bytea NOT NULL GENERATED ALWAYS AS (sha256(replace(document::text || type, '\\\\', '\\\\\\\\')::bytea)) STORED\" +\n ') ON COMMIT DROP',\n );\n }\n\n async completeInsert(tx: Knex.Transaction, type: string): Promise<void> {\n // Copy all new rows into the documents table\n await tx\n .insert(\n tx<RawDocumentRow>('documents_to_insert').select(\n 'type',\n 'document',\n 'hash',\n ),\n )\n .into(tx.raw('documents (type, document, hash)'))\n .onConflict('hash')\n .ignore();\n\n // Delete all documents that we don't expect (deleted and changed)\n await tx<RawDocumentRow>('documents')\n .where({ type })\n .whereNotIn(\n 'hash',\n tx<RawDocumentRow>('documents_to_insert').select('hash'),\n )\n .delete();\n }\n\n async insertDocuments(\n tx: Knex.Transaction,\n type: string,\n documents: IndexableDocument[],\n ): Promise<void> {\n // Insert all documents into the temporary table to process them later\n await tx<DocumentResultRow>('documents_to_insert').insert(\n documents.map(document => ({\n type,\n document,\n })),\n );\n }\n\n async query(\n tx: Knex.Transaction,\n searchQuery: PgSearchQuery,\n ): Promise<DocumentResultRow[]> {\n const { types, pgTerm, fields, offset, limit, options } = searchQuery;\n // TODO(awanlin): We should make the language a parameter so that we can support more then just english\n // Builds a query like:\n // SELECT ts_rank_cd(body, query) AS rank, type, document,\n // ts_headline('english', document, query) AS highlight\n // FROM documents, to_tsquery('english', 'consent') query\n // WHERE query @@ body AND (document @> '{\"kind\": \"API\"}')\n // ORDER BY rank DESC\n // LIMIT 10;\n const query = tx<DocumentResultRow>('documents');\n\n if (pgTerm) {\n query\n .from(tx.raw(\"documents, to_tsquery('english', ?) query\", pgTerm))\n .whereRaw('query @@ body');\n } else {\n query.from('documents');\n }\n\n if (types) {\n query.whereIn('type', types);\n }\n\n if (fields) {\n Object.keys(fields).forEach(key => {\n const value = fields[key];\n const valueArray = Array.isArray(value) ? value : [value];\n const valueCompare = valueArray\n .map(v => ({ [key]: v }))\n .map(v => JSON.stringify(v));\n query.whereRaw(\n `(${valueCompare.map(() => 'document @> ?').join(' OR ')})`,\n valueCompare,\n );\n });\n }\n\n query.select('type', 'document');\n\n if (pgTerm && options.useHighlight) {\n const headlineOptions = `MaxWords=${options.maxWords}, MinWords=${options.minWords}, ShortWord=${options.shortWord}, HighlightAll=${options.highlightAll}, MaxFragments=${options.maxFragments}, FragmentDelimiter=${options.fragmentDelimiter}, StartSel=${options.preTag}, StopSel=${options.postTag}`;\n query\n .select(tx.raw('ts_rank_cd(body, query) AS \"rank\"'))\n .select(\n tx.raw(\n `ts_headline(\\'english\\', document, query, '${headlineOptions}') as \"highlight\"`,\n ),\n )\n .orderBy('rank', 'desc');\n } else if (pgTerm && !options.useHighlight) {\n query\n .select(tx.raw('ts_rank_cd(body, query) AS \"rank\"'))\n .orderBy('rank', 'desc');\n } else {\n query.select(tx.raw('1 as rank'));\n }\n\n return await query.offset(offset).limit(limit);\n }\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BatchSearchEngineIndexer } from '@backstage/plugin-search-backend-node';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Knex } from 'knex';\nimport { DatabaseStore } from '../database';\n\nexport type PgSearchEngineIndexerOptions = {\n batchSize: number;\n type: string;\n databaseStore: DatabaseStore;\n};\n\nexport class PgSearchEngineIndexer extends BatchSearchEngineIndexer {\n private store: DatabaseStore;\n private type: string;\n private tx: Knex.Transaction | undefined;\n\n constructor(options: PgSearchEngineIndexerOptions) {\n super({ batchSize: options.batchSize });\n this.store = options.databaseStore;\n this.type = options.type;\n }\n\n async initialize(): Promise<void> {\n this.tx = await this.store.getTransaction();\n try {\n await this.store.prepareInsert(this.tx);\n } catch (e) {\n // In case of error, rollback the transaction and re-throw the error so\n // that the stream can be closed and destroyed properly.\n this.tx.rollback(e);\n throw e;\n }\n }\n\n async index(documents: IndexableDocument[]): Promise<void> {\n try {\n await this.store.insertDocuments(this.tx!, this.type, documents);\n } catch (e) {\n // In case of error, rollback the transaction and re-throw the error so\n // that the stream can be closed and destroyed properly.\n this.tx!.rollback(e);\n throw e;\n }\n }\n\n async finalize(): Promise<void> {\n // Attempt to complete and commit the transaction.\n try {\n await this.store.completeInsert(this.tx!, this.type);\n this.tx!.commit();\n } catch (e) {\n // Otherwise, rollback the transaction and re-throw the error so that the\n // stream can be closed and destroyed properly.\n this.tx!.rollback!(e);\n throw e;\n }\n }\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { PluginDatabaseManager } from '@backstage/backend-common';\nimport { SearchEngine } from '@backstage/plugin-search-common';\nimport {\n SearchQuery,\n IndexableResultSet,\n IndexableResult,\n} from '@backstage/plugin-search-common';\nimport { PgSearchEngineIndexer } from './PgSearchEngineIndexer';\nimport {\n DatabaseDocumentStore,\n DatabaseStore,\n PgSearchQuery,\n} from '../database';\nimport { v4 as uuid } from 'uuid';\nimport { Config } from '@backstage/config';\n\n/**\n * Search query that the Postgres search engine understands.\n * @public\n */\nexport type ConcretePgSearchQuery = {\n pgQuery: PgSearchQuery;\n pageSize: number;\n};\n\n/**\n * Options available for the Postgres specific query translator.\n * @public\n */\nexport type PgSearchQueryTranslatorOptions = {\n highlightOptions: PgSearchHighlightOptions;\n};\n\n/**\n * Postgres specific query translator.\n * @public\n */\nexport type PgSearchQueryTranslator = (\n query: SearchQuery,\n options: PgSearchQueryTranslatorOptions,\n) => ConcretePgSearchQuery;\n\n/**\n * Options to instantiate PgSearchEngine\n * @public\n */\nexport type PgSearchOptions = {\n database: PluginDatabaseManager;\n};\n\n/**\n * Options for highlighting search terms\n * @public\n */\nexport type PgSearchHighlightOptions = {\n useHighlight?: boolean;\n maxWords?: number;\n minWords?: number;\n shortWord?: number;\n highlightAll?: boolean;\n maxFragments?: number;\n fragmentDelimiter?: string;\n preTag: string;\n postTag: string;\n};\n\nexport class PgSearchEngine implements SearchEngine {\n private readonly highlightOptions: PgSearchHighlightOptions;\n\n /**\n * @deprecated This will be marked as private in a future release, please us fromConfig instead\n */\n constructor(private readonly databaseStore: DatabaseStore, config: Config) {\n const uuidTag = uuid();\n const highlightConfig = config.getOptionalConfig(\n 'search.pg.highlightOptions',\n );\n\n const highlightOptions: PgSearchHighlightOptions = {\n preTag: `<${uuidTag}>`,\n postTag: `</${uuidTag}>`,\n useHighlight: highlightConfig?.getOptionalBoolean('useHighlight') ?? true,\n maxWords: highlightConfig?.getOptionalNumber('maxWords') ?? 35,\n minWords: highlightConfig?.getOptionalNumber('minWords') ?? 15,\n shortWord: highlightConfig?.getOptionalNumber('shortWord') ?? 3,\n highlightAll:\n highlightConfig?.getOptionalBoolean('highlightAll') ?? false,\n maxFragments: highlightConfig?.getOptionalNumber('maxFragments') ?? 0,\n fragmentDelimiter:\n highlightConfig?.getOptionalString('fragmentDelimiter') ?? ' ... ',\n };\n this.highlightOptions = highlightOptions;\n }\n\n /**\n * @deprecated This will be removed in a future release, please us fromConfig instead\n */\n static async from(options: {\n database: PluginDatabaseManager;\n config: Config;\n }): Promise<PgSearchEngine> {\n return new PgSearchEngine(\n await DatabaseDocumentStore.create(await options.database.getClient()),\n options.config,\n );\n }\n\n static async fromConfig(config: Config, options: PgSearchOptions) {\n return new PgSearchEngine(\n await DatabaseDocumentStore.create(await options.database.getClient()),\n config,\n );\n }\n\n static async supported(database: PluginDatabaseManager): Promise<boolean> {\n return await DatabaseDocumentStore.supported(await database.getClient());\n }\n\n translator(\n query: SearchQuery,\n options: PgSearchQueryTranslatorOptions,\n ): ConcretePgSearchQuery {\n const pageSize = 25;\n const { page } = decodePageCursor(query.pageCursor);\n const offset = page * pageSize;\n // We request more result to know whether there is another page\n const limit = pageSize + 1;\n\n return {\n pgQuery: {\n pgTerm: query.term\n .split(/\\s/)\n .map(p => p.replace(/[\\0()|&:*!]/g, '').trim())\n .filter(p => p !== '')\n .map(p => `(${JSON.stringify(p)} | ${JSON.stringify(p)}:*)`)\n .join('&'),\n fields: query.filters as Record<string, string | string[]>,\n types: query.types,\n offset,\n limit,\n options: options.highlightOptions,\n },\n pageSize,\n };\n }\n\n setTranslator(translator: PgSearchQueryTranslator) {\n this.translator = translator;\n }\n\n async getIndexer(type: string) {\n return new PgSearchEngineIndexer({\n batchSize: 1000,\n type,\n databaseStore: this.databaseStore,\n });\n }\n\n async query(query: SearchQuery): Promise<IndexableResultSet> {\n const { pgQuery, pageSize } = this.translator(query, {\n highlightOptions: this.highlightOptions,\n });\n\n const rows = await this.databaseStore.transaction(async tx =>\n this.databaseStore.query(tx, pgQuery),\n );\n\n // We requested one result more than the page size to know whether there is\n // another page.\n const { page } = decodePageCursor(query.pageCursor);\n const hasNextPage = rows.length > pageSize;\n const hasPreviousPage = page > 0;\n const pageRows = rows.slice(0, pageSize);\n const nextPageCursor = hasNextPage\n ? encodePageCursor({ page: page + 1 })\n : undefined;\n const previousPageCursor = hasPreviousPage\n ? encodePageCursor({ page: page - 1 })\n : undefined;\n\n const results = pageRows.map(\n ({ type, document, highlight }, index): IndexableResult => ({\n type,\n document,\n rank: page * pageSize + index + 1,\n highlight: {\n preTag: pgQuery.options.preTag,\n postTag: pgQuery.options.postTag,\n fields: highlight\n ? {\n text: highlight.text,\n title: highlight.title,\n location: highlight.location,\n path: '',\n }\n : {},\n },\n }),\n );\n\n return { results, nextPageCursor, previousPageCursor };\n }\n}\n\nexport function decodePageCursor(pageCursor?: string): { page: number } {\n if (!pageCursor) {\n return { page: 0 };\n }\n\n return {\n page: Number(Buffer.from(pageCursor, 'base64').toString('utf-8')),\n };\n}\n\nexport function encodePageCursor({ page }: { page: number }): string {\n return Buffer.from(`${page}`, 'utf-8').toString('base64');\n}\n"],"names":["resolvePackagePath","BatchSearchEngineIndexer","uuid"],"mappings":";;;;;;;;AAAO,eAAe,yBAAyB,CAAC,IAAI,EAAE;AACtD,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE;AAC1C,IAAI,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;AACtE,GAAG;AACH,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAC7D,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AACxB,EAAE,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC;AAC7C,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;AACjD,EAAE,OAAO,YAAY,CAAC;AACtB;;ACPA,MAAM,aAAa,GAAGA,gCAAkB,CAAC,4CAA4C,EAAE,YAAY,CAAC,CAAC;AAC9F,MAAM,qBAAqB,CAAC;AACnC,EAAE,WAAW,CAAC,EAAE,EAAE;AAClB,IAAI,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AACjB,GAAG;AACH,EAAE,aAAa,MAAM,CAAC,IAAI,EAAE;AAC5B,I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AAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACrE,GAAG,CAAC;AACJ,CAAC;AACM,SAAS,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE;AAC3C,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC5D;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,87 @@
|
|
|
1
|
-
import { IndexableDocument, SearchQuery, IndexableResultSet } from '@backstage/plugin-search-common';
|
|
1
|
+
import { IndexableDocument, SearchQuery, SearchEngine, IndexableResultSet } from '@backstage/plugin-search-common';
|
|
2
2
|
import { Knex } from 'knex';
|
|
3
3
|
import { PluginDatabaseManager } from '@backstage/backend-common';
|
|
4
|
-
import { BatchSearchEngineIndexer
|
|
4
|
+
import { BatchSearchEngineIndexer } from '@backstage/plugin-search-backend-node';
|
|
5
|
+
import { Config } from '@backstage/config';
|
|
6
|
+
|
|
7
|
+
declare type PgSearchEngineIndexerOptions = {
|
|
8
|
+
batchSize: number;
|
|
9
|
+
type: string;
|
|
10
|
+
databaseStore: DatabaseStore;
|
|
11
|
+
};
|
|
12
|
+
declare class PgSearchEngineIndexer extends BatchSearchEngineIndexer {
|
|
13
|
+
private store;
|
|
14
|
+
private type;
|
|
15
|
+
private tx;
|
|
16
|
+
constructor(options: PgSearchEngineIndexerOptions);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
index(documents: IndexableDocument[]): Promise<void>;
|
|
19
|
+
finalize(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Search query that the Postgres search engine understands.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare type ConcretePgSearchQuery = {
|
|
27
|
+
pgQuery: PgSearchQuery;
|
|
28
|
+
pageSize: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Options available for the Postgres specific query translator.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
declare type PgSearchQueryTranslatorOptions = {
|
|
35
|
+
highlightOptions: PgSearchHighlightOptions;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Postgres specific query translator.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
declare type PgSearchQueryTranslator = (query: SearchQuery, options: PgSearchQueryTranslatorOptions) => ConcretePgSearchQuery;
|
|
42
|
+
/**
|
|
43
|
+
* Options to instantiate PgSearchEngine
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
declare type PgSearchOptions = {
|
|
47
|
+
database: PluginDatabaseManager;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Options for highlighting search terms
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
declare type PgSearchHighlightOptions = {
|
|
54
|
+
useHighlight?: boolean;
|
|
55
|
+
maxWords?: number;
|
|
56
|
+
minWords?: number;
|
|
57
|
+
shortWord?: number;
|
|
58
|
+
highlightAll?: boolean;
|
|
59
|
+
maxFragments?: number;
|
|
60
|
+
fragmentDelimiter?: string;
|
|
61
|
+
preTag: string;
|
|
62
|
+
postTag: string;
|
|
63
|
+
};
|
|
64
|
+
declare class PgSearchEngine implements SearchEngine {
|
|
65
|
+
private readonly databaseStore;
|
|
66
|
+
private readonly highlightOptions;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated This will be marked as private in a future release, please us fromConfig instead
|
|
69
|
+
*/
|
|
70
|
+
constructor(databaseStore: DatabaseStore, config: Config);
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated This will be removed in a future release, please us fromConfig instead
|
|
73
|
+
*/
|
|
74
|
+
static from(options: {
|
|
75
|
+
database: PluginDatabaseManager;
|
|
76
|
+
config: Config;
|
|
77
|
+
}): Promise<PgSearchEngine>;
|
|
78
|
+
static fromConfig(config: Config, options: PgSearchOptions): Promise<PgSearchEngine>;
|
|
79
|
+
static supported(database: PluginDatabaseManager): Promise<boolean>;
|
|
80
|
+
translator(query: SearchQuery, options: PgSearchQueryTranslatorOptions): ConcretePgSearchQuery;
|
|
81
|
+
setTranslator(translator: PgSearchQueryTranslator): void;
|
|
82
|
+
getIndexer(type: string): Promise<PgSearchEngineIndexer>;
|
|
83
|
+
query(query: SearchQuery): Promise<IndexableResultSet>;
|
|
84
|
+
}
|
|
5
85
|
|
|
6
86
|
interface PgSearchQuery {
|
|
7
87
|
fields?: Record<string, string | string[]>;
|
|
@@ -9,6 +89,7 @@ interface PgSearchQuery {
|
|
|
9
89
|
pgTerm?: string;
|
|
10
90
|
offset: number;
|
|
11
91
|
limit: number;
|
|
92
|
+
options: PgSearchHighlightOptions;
|
|
12
93
|
}
|
|
13
94
|
interface DatabaseStore {
|
|
14
95
|
transaction<T>(fn: (tx: Knex.Transaction) => Promise<T>): Promise<T>;
|
|
@@ -26,6 +107,7 @@ interface RawDocumentRow {
|
|
|
26
107
|
interface DocumentResultRow {
|
|
27
108
|
document: IndexableDocument;
|
|
28
109
|
type: string;
|
|
110
|
+
highlight: IndexableDocument;
|
|
29
111
|
}
|
|
30
112
|
|
|
31
113
|
declare class DatabaseDocumentStore implements DatabaseStore {
|
|
@@ -38,39 +120,7 @@ declare class DatabaseDocumentStore implements DatabaseStore {
|
|
|
38
120
|
prepareInsert(tx: Knex.Transaction): Promise<void>;
|
|
39
121
|
completeInsert(tx: Knex.Transaction, type: string): Promise<void>;
|
|
40
122
|
insertDocuments(tx: Knex.Transaction, type: string, documents: IndexableDocument[]): Promise<void>;
|
|
41
|
-
query(tx: Knex.Transaction,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
declare type PgSearchEngineIndexerOptions = {
|
|
45
|
-
batchSize: number;
|
|
46
|
-
type: string;
|
|
47
|
-
databaseStore: DatabaseStore;
|
|
48
|
-
};
|
|
49
|
-
declare class PgSearchEngineIndexer extends BatchSearchEngineIndexer {
|
|
50
|
-
private store;
|
|
51
|
-
private type;
|
|
52
|
-
private tx;
|
|
53
|
-
constructor(options: PgSearchEngineIndexerOptions);
|
|
54
|
-
initialize(): Promise<void>;
|
|
55
|
-
index(documents: IndexableDocument[]): Promise<void>;
|
|
56
|
-
finalize(): Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare type ConcretePgSearchQuery = {
|
|
60
|
-
pgQuery: PgSearchQuery;
|
|
61
|
-
pageSize: number;
|
|
62
|
-
};
|
|
63
|
-
declare class PgSearchEngine implements SearchEngine {
|
|
64
|
-
private readonly databaseStore;
|
|
65
|
-
constructor(databaseStore: DatabaseStore);
|
|
66
|
-
static from(options: {
|
|
67
|
-
database: PluginDatabaseManager;
|
|
68
|
-
}): Promise<PgSearchEngine>;
|
|
69
|
-
static supported(database: PluginDatabaseManager): Promise<boolean>;
|
|
70
|
-
translator(query: SearchQuery): ConcretePgSearchQuery;
|
|
71
|
-
setTranslator(translator: (query: SearchQuery) => ConcretePgSearchQuery): void;
|
|
72
|
-
getIndexer(type: string): Promise<PgSearchEngineIndexer>;
|
|
73
|
-
query(query: SearchQuery): Promise<IndexableResultSet>;
|
|
123
|
+
query(tx: Knex.Transaction, searchQuery: PgSearchQuery): Promise<DocumentResultRow[]>;
|
|
74
124
|
}
|
|
75
125
|
|
|
76
|
-
export { ConcretePgSearchQuery, DatabaseDocumentStore, DatabaseStore, PgSearchEngine, PgSearchEngineIndexer, PgSearchEngineIndexerOptions, PgSearchQuery, RawDocumentRow };
|
|
126
|
+
export { ConcretePgSearchQuery, DatabaseDocumentStore, DatabaseStore, PgSearchEngine, PgSearchEngineIndexer, PgSearchEngineIndexerOptions, PgSearchHighlightOptions, PgSearchOptions, PgSearchQuery, PgSearchQueryTranslator, PgSearchQueryTranslatorOptions, RawDocumentRow };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-search-backend-module-pg",
|
|
3
3
|
"description": "A module for the search backend that implements search using PostgreSQL",
|
|
4
|
-
"version": "0.3.5
|
|
4
|
+
"version": "0.3.5",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -23,19 +23,23 @@
|
|
|
23
23
|
"clean": "backstage-cli package clean"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@backstage/backend-common": "^0.14.1
|
|
27
|
-
"@backstage/
|
|
28
|
-
"@backstage/plugin-search-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
26
|
+
"@backstage/backend-common": "^0.14.1",
|
|
27
|
+
"@backstage/config": "^1.0.1",
|
|
28
|
+
"@backstage/plugin-search-backend-node": "^1.0.0",
|
|
29
|
+
"@backstage/plugin-search-common": "^1.0.0",
|
|
30
|
+
"knex": "^2.0.0",
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"uuid": "^8.3.2"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@backstage/backend-test-utils": "^0.1.26
|
|
34
|
-
"@backstage/cli": "^0.
|
|
35
|
+
"@backstage/backend-test-utils": "^0.1.26",
|
|
36
|
+
"@backstage/cli": "^0.18.0"
|
|
35
37
|
},
|
|
36
38
|
"files": [
|
|
37
39
|
"dist",
|
|
38
|
-
"migrations"
|
|
40
|
+
"migrations",
|
|
41
|
+
"config.d.ts"
|
|
39
42
|
],
|
|
40
|
-
"
|
|
43
|
+
"configSchema": "config.d.ts",
|
|
44
|
+
"gitHead": "999878d8f1ae30f6a15925816af2016cb9d717a1"
|
|
41
45
|
}
|