cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting ResultSet via SortedResultSet

k_warcaba
Champ in-the-making
Champ in-the-making
Hi all,

I have a problem with sorting ResultSet via SortedResultSet. Here is my code:

            
            ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, query);

            SearchParameters parameters = new SearchParameters();
            String field = "{http://www.alfresco.org/model/content/1.0}created";
            parameters.addSort(field, false);

            List<NodeRef> nodes = new SortedResultSet(resultSet, nodeService, parameters, namespaceService).getNodeRefs().subList(0,10);

I want to sort the resultset using {http://www.alfresco.org/model/content/1.0}created field. It doesn't work and I do not know why.

Can anyone help me with this issue?

Thanks in Advance,
Kamil Warcaba
2 REPLIES 2

rliu
Champ in-the-making
Champ in-the-making
Ha! …. Lucene has roughed me up a couple days and I hope nobody had to go thru the battles I had to go thru.

            
SearchParameters parameters = new SearchParameters();
String field = "{http://www.alfresco.org/model/content/1.0}created";
parameters.addSort(field, false);

Try the following:

SearchParameters parameters = new SearchParameters();
String field = "{http://www.alfresco.org/model/content/1.0}created";
parameters.addSort(org.alfresco.repo.search.impl.lucene.QueryParser.escape(field), false);

This should work, though, if you want to make life simpler, use the prefix property naming convention:

String field = org.alfresco.repo.search.impl.lucene.QueryParser.escape("@cm:created");

Reference: http://lucene.apache.org/java/2_4_1/api/org/apache/lucene/queryParser/QueryParser.html#escape(java.l...

agrosu
Champ in-the-making
Champ in-the-making
Hi,

Just having the same case.
The problem is the ommission of the "@" in the sort clause.
Old sort
String field = "{http://www.alfresco.org/model/content/1.0}created";
Correct sort:
String field = "@{http://www.alfresco.org/model/content/1.0}created";

Hope that helps
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.