create backend modules for search engines
Signed-off-by: Emma Indal <emma.indahl@gmail.com>
This commit is contained in:
@@ -20,6 +20,10 @@ import { createBackend } from '@backstage/backend-defaults';
|
||||
import { appPlugin } from '@backstage/plugin-app-backend/alpha';
|
||||
import { todoPlugin } from '@backstage/plugin-todo-backend';
|
||||
import { techdocsPlugin } from '@backstage/plugin-techdocs-backend/alpha';
|
||||
import { searchPlugin } from '@backstage/plugin-search-backend';
|
||||
import { elasticSearchEngineModule } from '@backstage/plugin-search-backend-module-elasticsearch';
|
||||
import { pgSearchEngineModule } from '@backstage/plugin-search-backend-module-pg';
|
||||
import { lunrSearchEngineModule } from '@backstage/plugin-search-backend-node/';
|
||||
|
||||
const backend = createBackend();
|
||||
|
||||
@@ -28,4 +32,10 @@ backend.add(catalogModuleTemplateKind());
|
||||
backend.add(appPlugin({ appPackageName: 'example-app' }));
|
||||
backend.add(todoPlugin());
|
||||
backend.add(techdocsPlugin());
|
||||
|
||||
backend.add(searchPlugin());
|
||||
backend.add(elasticSearchEngineModule());
|
||||
backend.add(pgSearchEngineModule());
|
||||
backend.add(lunrSearchEngineModule());
|
||||
|
||||
backend.start();
|
||||
|
||||
+31
-1
@@ -30,9 +30,17 @@ import { ElasticSearchClientWrapper } from './ElasticSearchClientWrapper';
|
||||
import { ElasticSearchCustomIndexTemplate } from './types';
|
||||
import { ElasticSearchSearchEngineIndexer } from './ElasticSearchSearchEngineIndexer';
|
||||
import { Logger } from 'winston';
|
||||
import { MissingIndexError } from '@backstage/plugin-search-backend-node';
|
||||
import {
|
||||
MissingIndexError,
|
||||
searchEngineRegistryExtensionPoint,
|
||||
} from '@backstage/plugin-search-backend-node';
|
||||
import esb from 'elastic-builder';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
|
||||
export type { ElasticSearchClientOptions };
|
||||
|
||||
@@ -521,3 +529,25 @@ export async function createElasticSearchClientOptions(
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
export const elasticSearchEngineModule = createBackendModule({
|
||||
moduleId: 'elasticSearchEngineModule',
|
||||
pluginId: 'search-backend',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
logger: coreServices.logger,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, logger, config }) {
|
||||
searchEngineRegistry.setSearchEngine(
|
||||
await ElasticSearchSearchEngine.fromConfig({
|
||||
logger: loggerToWinstonLogger(logger),
|
||||
config: config,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
export {
|
||||
decodePageCursor as decodeElasticSearchPageCursor,
|
||||
ElasticSearchSearchEngine,
|
||||
elasticSearchEngineModule,
|
||||
} from './ElasticSearchSearchEngine';
|
||||
export { isOpenSearchCompatible } from './ElasticSearchClientOptions';
|
||||
export type {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
export {
|
||||
decodeElasticSearchPageCursor,
|
||||
ElasticSearchSearchEngine,
|
||||
elasticSearchEngineModule,
|
||||
isOpenSearchCompatible,
|
||||
} from './engines';
|
||||
export type {
|
||||
|
||||
@@ -30,6 +30,11 @@ import {
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node';
|
||||
|
||||
/**
|
||||
* Search query that the Postgres search engine understands.
|
||||
@@ -244,3 +249,24 @@ export function decodePageCursor(pageCursor?: string): { page: number } {
|
||||
export function encodePageCursor({ page }: { page: number }): string {
|
||||
return Buffer.from(`${page}`, 'utf-8').toString('base64');
|
||||
}
|
||||
|
||||
export const pgSearchEngineModule = createBackendModule({
|
||||
moduleId: 'pgSearchEngineModule',
|
||||
pluginId: 'search-backend',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
database: coreServices.database,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, database, config }) {
|
||||
searchEngineRegistry.setSearchEngine(
|
||||
await PgSearchEngine.fromConfig(config, {
|
||||
database: database,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { PgSearchEngine } from './PgSearchEngine';
|
||||
export { PgSearchEngine, pgSearchEngineModule } from './PgSearchEngine';
|
||||
export type {
|
||||
ConcretePgSearchQuery,
|
||||
PgSearchQueryTranslatorOptions,
|
||||
|
||||
@@ -26,6 +26,12 @@ import lunr from 'lunr';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Logger } from 'winston';
|
||||
import { LunrSearchEngineIndexer } from './LunrSearchEngineIndexer';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { searchEngineRegistryExtensionPoint } from '../extensions';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
|
||||
/**
|
||||
* Type of translated query for the Lunr Search Engine.
|
||||
@@ -334,3 +340,21 @@ export function parseHighlightFields({
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export const lunrSearchEngineModule = createBackendModule({
|
||||
moduleId: 'lunrSearchEngineModule',
|
||||
pluginId: 'search-backend',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
logger: coreServices.logger,
|
||||
},
|
||||
async init({ searchEngineRegistry, logger }) {
|
||||
searchEngineRegistry.setSearchEngine(
|
||||
new LunrSearchEngine({ logger: loggerToWinstonLogger(logger) }),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { LunrSearchEngine } from './LunrSearchEngine';
|
||||
export { LunrSearchEngine, lunrSearchEngineModule } from './LunrSearchEngine';
|
||||
export type {
|
||||
ConcreteLunrQuery,
|
||||
LunrQueryTranslator,
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
export { IndexBuilder } from './IndexBuilder';
|
||||
export { Scheduler } from './Scheduler';
|
||||
export * from './collators';
|
||||
export { LunrSearchEngine } from './engines';
|
||||
export { LunrSearchEngine, lunrSearchEngineModule } from './engines';
|
||||
export type {
|
||||
ConcreteLunrQuery,
|
||||
LunrQueryTranslator,
|
||||
|
||||
@@ -21,6 +21,4 @@
|
||||
*/
|
||||
|
||||
export * from './service/router';
|
||||
|
||||
// TODO: export as alfa subpath
|
||||
export { searchPlugin } from './plugin';
|
||||
export * from './plugin';
|
||||
|
||||
Reference in New Issue
Block a user