cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting of Contents based on two fields

chai
Champ in-the-making
Champ in-the-making
Hi,

I want to sort the contents from Alfresco based on two fields. Please note the below points:
1) The first field used here for sorting (content_date) has only date part and not time part.
    So if there are more than one content with same content_date, I want them to be sorted based on modified date.
2) Sorting based on first field (content_date) alone works fine.
3) Sorting based on second field (modified) alone also works fine.
4) Sorting based on both fields together doesn't seem to be working.

My code looks like this:

import org.alfresco.service.cmr.search.SearchParameters;
……

   SearchParameters searchParameters = new SearchParameters();
   searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE);
   ….
   searchParameters.addSort("@{http://www.myModel.com}content_date", false);
   searchParameters.addSort("@{http://www.alfresco.org/model/content/1.0}modified", false);
   ….

If anyone has implemented this, please provide your inputs.

Thank you.
1 REPLY 1

chai
Champ in-the-making
Champ in-the-making
One more point to add to the above post:

If I sort based on the fields content_date and name(or any other field other than modified date), it works perfectly fine.

      …..
      searchParameters.addSort("@{http://www.myModel.com}content_date", false);
      searchParameters.addSort("@{http://www.alfresco.org/model/content/1.0}name", false);
      …..

Also, the following code works.

      …..
      searchParameters.addSort("@{http://www.myModel.com}name", false);
      searchParameters.addSort("@{http://www.alfresco.org/model/content/1.0}content_date", false);
      …..


The issue is present only when the secondary sort field is modified date.