Alfresco provides a Search API for making queries against the Lucene or SOLR index. The SearchService is utilized for making queries, and queries are built up using the SearchParameters class. The SearchParameters class allows for adding one or more sort clauses when performing a search against SOLR.
The Alfresco Wiki provides a good introduction into utilizing the SearchServer and SearchParameters:
The focus of this article is on a change between Lucene and SOLR around sorting on a property within a type. In Lucene, it was possible to sort with a property regardless of the “Tokenised” setting for that property. However, there is a change between Lucene and SOLR that prevents this. SOLR will throw an error if a sort is attempted against a property where ‘tokenised’ is set to ‘true’. An example error message is provided below:
- 2013-09-20 13:23:06,768 ERROR [solr.core.SolrCore] [http-8443-5] java.lang.UnsupportedOperationException: Ordering not supported for @bf:myProperty
This issue will not impact all property types in Alfresco; however, both the “d:text” and “d:mltext” property types will not allow for sorting unless the settings are changed from the default values.
The default index settings for a property are provided below. By default, ‘tokenised’ is set to ‘true’:
<index enabled="true"> <atomic>true</atomic> <stored>false</stored> <tokenised>true</tokenised> </index>
It is possible to change the tokenised setting in the definition of the property in the model file to either ‘false’ or to ‘both’. Either of these settings will allow for sorting on the field. An example of using ‘both’ is provided below:
<index enabled="true"> <atomic>true</atomic> <stored>false</stored> <tokenised>both</tokenised> </index>
More information about setting indexing values is provided on the Alfresco Wiki:
It is important to think about the requirements for searching and sorting ahead of time, as it does require a change to the model if a change needs to be made. In addition, the SOLR index will need to be rebuilt once the change has been made.
This issue could also impact migrations from Lucene to SOLR, as this error is not thrown when Lucene is utilized.