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?

    We rely on cookies

    to optimize our communication and to enhance your customer experience. By clicking on the Accept and Close button, you agree to the collection of cookies. You can also adjust your preferences by clicking on Manage Preferences. For more information please see our Privacy policy.

    Manage cookies
    Accept & close

    Cookies preferences

    Accept & close
    Back