Skip to content

Commit

Permalink
Fixes Seneca-CDOT#1224: Show all posts for an author sorted by date w…
Browse files Browse the repository at this point in the history
…hen searching by Author (Seneca-CDOT#1256)

* sort search results by date

* minor edit

* changed sort to only work with author filter
  • Loading branch information
joelazwar committed Nov 15, 2020
1 parent f6a5274 commit e45b521
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/backend/utils/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ const createFieldsFromFilter = (filter) => {
}
};

const sortFromFilter = (filter) => {
switch (filter) {
case 'author':
return [{ published: { order: 'desc' } }];
case 'post':
default:
return undefined;
}
};

/**
* Searches text in elasticsearch
* @param textToSearch
Expand All @@ -82,6 +92,7 @@ const search = async (textToSearch, filter = 'post') => {
fields: createFieldsFromFilter(filter),
},
},
sort: sortFromFilter(filter),
};

const {
Expand Down

0 comments on commit e45b521

Please sign in to comment.