Querying the latest versions of your document

Lets say I have 3 documents

  • Doc A
  • Doc B
  • Doc C

and each document is versioned by timeStamp. The Documents will follow this schema:

id: uniqueID
title: DocA, DocB, DocC, etc...
timeStamp: date
documentContents: text

How would I query in a way such that I query only the latest document (defined by timestamp) for each unique title?

So I might want documents which contain the word "dog" but DocA and DocB might have it in multiple versions. The query will return every version of DocA and DocB which contains "dog".

I only want the search result to return only the latest versions of DocA and DocB.

Take a look at field collapsing. This would allow you to sort the results on the timestamp, and only return the most recent version of a document, when collapsing on the title field.

that's amazing. Thank you very much.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.