Skip to content

Commit

Permalink
fix settings meilisearch
Browse files Browse the repository at this point in the history
  • Loading branch information
wulff007 committed Oct 28, 2024
1 parent 6a2eef7 commit ab3ebd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/data-indexer/data-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ export class DataIndexer {
if (!index) {
await this.createIndex(indexUid)
index = await this.getIndex(indexUid)
await this.updateIndexSettings(index/*, params.dataSourceConfig.fields*/)
await this.updateIndexSettings(index, params.dataSourceConfig.fields)
} else if (!params.ids || !params.ids.length){
newIndexUid = `${indexUid}__new__`
await this.searchClient.deleteIndexIfExists(newIndexUid)
await this.createIndex(newIndexUid)
index = await this.getIndex(newIndexUid)
await this.updateIndexSettings(index, /*params.dataSourceConfig.fields*/)
await this.updateIndexSettings(index, params.dataSourceConfig.fields)

}

Expand Down Expand Up @@ -475,20 +475,23 @@ export class DataIndexer {
throw task.error
}

async updateIndexSettings(index: Index/*, fields: DatasourceField[]*/) {
async updateIndexSettings(index: Index, fields: DatasourceField[]) {

//let sort = fields.filter(f=>f.sortable).map(f=>f.alias)
//let filter = fields.filter(f=>f.filterable).map(f=>f.alias)
let filter = fields.filter(f=>f.filterable).map(f=>f.alias)
//let search = fields.filter(f=>f.searchable).map(f=>f.alias)

// Need add filterable link field id to index linked data after update linked item
// fields.filter(f => f.type === 'link' || f.type === 'enum').forEach(i => {
// filter.push(`${i.alias}.id`)
// })
//Need add filterable link field id to index linked data after update linked item
fields.filter(f => f.type === 'link' || f.type === 'enum').forEach(i => {
filter.push(`${i.alias}.id`)
})

console.log(filter)

let taskUid = (await index.updateSettings({
sortableAttributes: ['*'],
displayedAttributes: ['*'],
filterableAttributes: ['*'],
filterableAttributes: filter,
searchableAttributes: ['*']
})).taskUid

Expand Down
3 changes: 2 additions & 1 deletion src/datasources/datasourceV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ export class DataSourceV2Service {
await this.indexer.createIndex(indexUid)
index = await this.indexer.getIndex(indexUid)
}
await this.indexer.updateIndexSettings(index, /*ds.fields*/)
let full = await this.getConfigByAlias(alias, true)
await this.indexer.updateIndexSettings(index, full.fields)
await this.indexer.dataReindex({dataSourceConfig: ds}, context)
}

Expand Down

0 comments on commit ab3ebd2

Please sign in to comment.