Merge pull request #16710 from backstage/search/backend-system-migration

[Search] Migrate search to new backend system
This commit is contained in:
Camila Belo
2023-03-22 09:21:15 +01:00
committed by GitHub
68 changed files with 1898 additions and 116 deletions
@@ -0,0 +1,50 @@
## API Report File for "@backstage/plugin-search-backend-node"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { DocumentTypeInfo } from '@backstage/plugin-search-common';
import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { RegisterCollatorParameters } from '@backstage/plugin-search-backend-node';
import { RegisterDecoratorParameters } from '@backstage/plugin-search-backend-node';
import { SearchEngine } from '@backstage/plugin-search-common';
import { ServiceRef } from '@backstage/backend-plugin-api';
// @alpha
export interface SearchEngineRegistryExtensionPoint {
// (undocumented)
setSearchEngine(searchEngine: SearchEngine): void;
}
// @alpha
export const searchEngineRegistryExtensionPoint: ExtensionPoint<SearchEngineRegistryExtensionPoint>;
// @alpha
export interface SearchIndexRegistryExtensionPoint {
// (undocumented)
addCollator(options: RegisterCollatorParameters): void;
// (undocumented)
addDecorator(options: RegisterDecoratorParameters): void;
}
// @alpha
export const searchIndexRegistryExtensionPoint: ExtensionPoint<SearchIndexRegistryExtensionPoint>;
// @alpha
export interface SearchIndexService {
getDocumentTypes(): Record<string, DocumentTypeInfo>;
start(options: SearchIndexServiceStartOptions): Promise<void>;
}
// @alpha
export const searchIndexServiceRef: ServiceRef<SearchIndexService, 'plugin'>;
// @alpha
export type SearchIndexServiceStartOptions = {
searchEngine: SearchEngine;
collators: RegisterCollatorParameters[];
decorators: RegisterDecoratorParameters[];
};
// (No @packageDocumentation comment for this package)
```
+17 -3
View File
@@ -6,9 +6,22 @@
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
"access": "public"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"backstage": {
"role": "node-library"
@@ -24,6 +37,7 @@
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/backend-tasks": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
+159
View File
@@ -0,0 +1,159 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Logger } from 'winston';
import {
createServiceRef,
createServiceFactory,
coreServices,
} from '@backstage/backend-plugin-api';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import {
DocumentTypeInfo,
SearchEngine,
} from '@backstage/plugin-search-common';
import { createExtensionPoint } from '@backstage/backend-plugin-api';
import {
RegisterCollatorParameters,
RegisterDecoratorParameters,
} from '@backstage/plugin-search-backend-node';
import { IndexBuilder } from './IndexBuilder';
/**
* @alpha
* Options for build method on {@link SearchIndexService}.
*/
export type SearchIndexServiceStartOptions = {
searchEngine: SearchEngine;
collators: RegisterCollatorParameters[];
decorators: RegisterDecoratorParameters[];
};
/**
* @alpha
* Interface for implementation of index service.
*/
export interface SearchIndexService {
/**
* Starts indexing process
*/
start(options: SearchIndexServiceStartOptions): Promise<void>;
/**
* Returns an index types list.
*/
getDocumentTypes(): Record<string, DocumentTypeInfo>;
}
/**
* @alpha
* Interface for search index registry extension point.
*/
export interface SearchIndexRegistryExtensionPoint {
addCollator(options: RegisterCollatorParameters): void;
addDecorator(options: RegisterDecoratorParameters): void;
}
/**
* @alpha
* Interface for search engine registry extension point.
*/
export interface SearchEngineRegistryExtensionPoint {
setSearchEngine(searchEngine: SearchEngine): void;
}
type DefaultSearchIndexServiceOptions = {
logger: Logger;
};
/**
* @alpha
* Reponsible for register the indexing task and start the schedule.
*/
class DefaultSearchIndexService implements SearchIndexService {
private logger: Logger;
private indexBuilder: IndexBuilder | null = null;
private constructor(options: DefaultSearchIndexServiceOptions) {
this.logger = options.logger;
}
static fromConfig(options: DefaultSearchIndexServiceOptions) {
return new DefaultSearchIndexService(options);
}
async start(options: SearchIndexServiceStartOptions): Promise<void> {
this.indexBuilder = new IndexBuilder({
logger: this.logger,
searchEngine: options.searchEngine,
});
options.collators.forEach(collator =>
this.indexBuilder?.addCollator(collator),
);
options.decorators.forEach(decorator =>
this.indexBuilder?.addDecorator(decorator),
);
const { scheduler } = await this.indexBuilder?.build();
scheduler.start();
}
getDocumentTypes(): Record<string, DocumentTypeInfo> {
return this.indexBuilder?.getDocumentTypes() ?? {};
}
}
/**
* @alpha
* Service that builds a search index.
*/
export const searchIndexServiceRef = createServiceRef<SearchIndexService>({
id: 'search.index.service',
defaultFactory: async service =>
createServiceFactory({
service,
deps: {
logger: coreServices.logger,
},
factory({ logger }) {
return DefaultSearchIndexService.fromConfig({
logger: loggerToWinstonLogger(logger),
});
},
}),
});
/**
* @alpha
* Extension point for register a search engine.
*/
export const searchEngineRegistryExtensionPoint =
createExtensionPoint<SearchEngineRegistryExtensionPoint>({
id: 'search.engine.registry',
});
/**
* @alpha
* Extension point for registering collators and decorators
*/
export const searchIndexRegistryExtensionPoint =
createExtensionPoint<SearchIndexRegistryExtensionPoint>({
id: 'search.index.registry',
});