Sorting search results

Sorting search results is very simple in Solr. You however can only sort on stored fields. If you sort on non-stored fields, you might get unexpected order of the results.

Assume date field is stored in Solr schema.xml

<field name="date" type="tdate" indexed="true" stored="true" />

Date field is stored and thus can be sorted on:

@Override
public void doBeforeRender(final HstRequest request,
                           final HstResponse response)
                                   throws HstComponentException {
  HippoSolrClient solrClient =
      HstServices.getComponentManager().getComponent(
                    HippoSolrClient.class.getName(), "org.hippoecm.hst.solr");
  HippoQuery hippoQuery = solrClient.createQuery(query);
  hippoQuery.getSolrQuery().addSortField("date", SolrQuery.ORDER.desc);
  HippoQueryResult result = hippoQuery.execute();
}
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?