Skip to content

Commit

Permalink
Return related materials ordered by query instead of covers
Browse files Browse the repository at this point in the history
In the current version we retrieve object ids from search result,
pass these to the cover service in the same order and merge material 
data intro the provided results.

However practice has shown that the cover service does not
necessarily preserve the order of the requested ids in the response.
This leads to a situation where the related materials will not have
the same order as in the linked search result. 

To preserve the order of the materials from the search result we 
merge cover data into the materials instead and filter away any 
materials without a cover.
  • Loading branch information
kasperg committed Jul 8, 2020
1 parent e0dc8bf commit 7ce2fae
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/apps/related-materials/related-materials.entry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ async function getRelatedMaterials({
// Remove covers which do not have the requested cover size.
const covers = coverData.filter(cover => cover.imageUrls[coverSize]?.url);

function mergeCoverAndMaterials(cover) {
function locateCoverMaterial(material) {
function mergeMaterialsAndCovers(material) {
function locateMaterialCover(cover) {
return material.pid[0] === cover.id;
}
const material = materials.find(locateCoverMaterial);
const cover = covers.find(locateMaterialCover);
return { ...Material.format(material), cover };
}

const coveredMaterials = covers.map(mergeCoverAndMaterials);
return coveredMaterials;
const coveredMaterials = materials.map(mergeMaterialsAndCovers);
// Remove materials without covers.
return coveredMaterials.filter(material => material.cover);
}

/**
Expand Down

0 comments on commit 7ce2fae

Please sign in to comment.