Skip to content

Commit

Permalink
search: catch more error scenarios while indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyDo committed Feb 7, 2024
1 parent 2ff7709 commit 7371599
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/common/helpers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ async function _fetchEntityModelsForESResults(orm, results) {
const area = await Area.forge({gid: entityStub.bbid})
.fetch({withRelated: ['areaType']});

const areaJSON = area.toJSON();
const areaJSON = area.toJSON({omitPivot: true});
const areaParents = await area.parents();
areaJSON.defaultAlias = {
Expand Down Expand Up @@ -161,14 +160,14 @@ export async function _bulkIndexEntities(entities) {
// eslint-disable-next-line no-await-in-loop
const response = await _client.bulk({
body: bulkOperations
});
}).catch(error => { log.error('error bulk indexing entities for search:', error); break; });

/*
* In case of failed index operations, the promise won't be rejected;
* instead, we have to inspect the response and respond to any failures
* individually.
*/
if (response.errors === true) {
if (response?.errors === true) {
entitiesToIndex = response.items.reduce((accumulator, item) => {
// We currently only handle queue overrun
if (item.index.status === httpStatus.TOO_MANY_REQUESTS) {
Expand Down Expand Up @@ -268,7 +267,7 @@ export function deleteEntity(entity) {
}

export function refreshIndex() {
return _client.indices.refresh({index: _index});
return _client.indices.refresh({index: _index}).catch(error => { log.error('error refreshing search index:', error); });
}

export async function generateIndex(orm) {
Expand Down Expand Up @@ -414,14 +413,14 @@ export async function generateIndex(orm) {
const relationshipSet = workEntity.related('relationshipSet');
if (relationshipSet) {
const authorWroteWorkRels = relationshipSet.related('relationships')?.filter(relationshipModel => relationshipModel.get('typeId') === 8);
const authorNames = authorWroteWorkRels.map(relationshipModel => {
const authorNames = [];
authorWroteWorkRels.forEach(relationshipModel => {
// Search for the Author in the already fetched BookshelfJS Collection
const source = authorsCollection.get(relationshipModel.get('sourceBbid'));
if (!source) {
// This shouldn't happen, but just in case
return null;
const name = source?.related('defaultAlias')?.get('name');
if (name) {
authorNames.push(name);
}
return source.toJSON().defaultAlias.name;
});
workEntity.set('authors', authorNames);
}
Expand Down

0 comments on commit 7371599

Please sign in to comment.