File tree Expand file tree Collapse file tree 2 files changed +18
-17
lines changed
Expand file tree Collapse file tree 2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change @@ -65,22 +65,23 @@ export class SearchService {
6565 } ;
6666
6767 private setupIndexes = async ( ) : Promise < void > => {
68- await this . meilisearch . createIndex ( "project" , {
69- primaryKey : "id" ,
70- } ) ;
71- this . logger . info ( { message : "project index created" } ) ;
72-
73- await this . meilisearch . createIndex ( "contribution" , {
74- primaryKey : "id" ,
75- } ) ;
76- this . logger . info ( { message : "contribution index created" } ) ;
77-
78- await this . meilisearch . createIndex ( "contributor" , {
79- primaryKey : "id" ,
80- } ) ;
81- this . logger . info ( { message : "contributor index created" } ) ;
68+ await this . upsertIndex ( "project" ) ;
69+ await this . upsertIndex ( "contribution" ) ;
70+ await this . upsertIndex ( "contributor" ) ;
8271 } ;
8372
73+ private async upsertIndex ( index : SearchType ) : Promise < void > {
74+ try {
75+ await this . meilisearch . getIndex ( index ) ;
76+ this . logger . info ( { message : `${ index } index already exists` } ) ;
77+ } catch {
78+ await this . meilisearch . createIndex ( index , {
79+ primaryKey : "id" ,
80+ } ) ;
81+ this . logger . info ( { message : `${ index } index created` } ) ;
82+ }
83+ }
84+
8485 private async updateFilterableAttributes ( ) : Promise < void > {
8586 await this . meilisearch
8687 . index ( "project" )
Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ export interface GetSearchResponse extends GeneralResponse {
88 searchResults : SearchResults ;
99}
1010
11- export type SearchResults = MultiSearchResponse < SearchItem > ;
12-
13- type SearchItem = ProjectEntity | ContributionEntity | ContributorEntity ;
11+ export type SearchResults = MultiSearchResponse <
12+ ProjectEntity | ContributionEntity | ContributorEntity
13+ > ;
1414
1515export type SearchType = "project" | "contribution" | "contributor" ;
You can’t perform that action at this time.
0 commit comments