Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/server/routes/api/document/crossref/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ const ID_TYPE = Object.freeze({
* @returns
*/
const match = ( paperId, IdType, hits ) => {
const orderByCreation = works => {
const byCreated = ( a, b ) => b.created.timestamp - a.created.timestamp;

let ordered = works;
const top = _.head( works );
if( top ) ordered = works.filter( h => h.score === top.score );
return ordered.sort( byCreated );
};

const byCreated = ( a, b ) => b.created.timestamp - a.created.timestamp;
const sanitize = raw => {
const trimmed = _.trim( raw , ' .');
const lower = _.toLower( trimmed );
Expand Down Expand Up @@ -56,9 +48,9 @@ const match = ( paperId, IdType, hits ) => {

// Filter hits based on match to title (partial), DOI (exact
const matches = hits.filter( workMatchesPaperId );
// Order based on score, then created date
const ordered = orderByCreation( matches );
return _.head( ordered );
// Order by created date
matches.sort( byCreated );
return _.head( matches );
};

/**
Expand Down
Loading