create backend modules for search engines

Signed-off-by: Emma Indal <emma.indahl@gmail.com>
This commit is contained in:
Emma Indal
2023-03-01 21:47:19 +01:00
committed by Camila Belo
parent 406647ea6b
commit 97e5d514d1
10 changed files with 97 additions and 7 deletions
@@ -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,
+1 -1
View File
@@ -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,