Show groups by most recent member

I have a database of quotes and sources. They are set up as indivdual records, with this basic structure:

  sourceId: 123, 
  quote: "This is awesome",
  objectID: 456,
  timeStamp: Oct 7 2020

I want my search results to be ordered by the most recent quote, then grouped by sourceId. So all the other quotes for the source 123 would appear in the group, even if they are much older than the newest quote.

I’ve read How to Group Results but this seems like it refers to a different goal than what I’m trying to achieve.

Any guidance would be appreciated, thanks.

Hi @jmc, To sort by timestamp, you will need to convert your timestamp to a unix timestamp so that it is a number instead of a string. You could then sort by timestamp first and sourceId next to group the records. However, using the sortBy will lose the relevancy for your search query.

Alternatively, you could use the timestamp and sourceId as custom ranking factors. This will allow your results to be ranked by relevancy, but the timestamp and sourceId will break any ties for records that match in relevancy.

To learn more: sorting and ranking.