I want to change the default sorting order of a pre-populated Solr search page (the option "Show enabled facets' blocks in their configured regions and first page of all available results" under "Behavior on empty search" of the Advanced Search Options). I thought the solution would be setting a custom filter but I cannot find the right syntax: I tried everything from "solrsort=ds_created:desc" to "sort=created:desc" and all the variants between... but I failed... Anyone may help me please?

1 Answer 1


Just a regular space seems to be working for me. Add the following to the end of your search URL: "&solrsort=ds_created desc".

Just to be sure though, you can always go to the following reports page, to make sure the ds_created field has been indexed. You can see all the fields apachesolr has in its index there: /admin/reports/apachesolr

Let me know if that helps!

============== EDIT ===================

Another option I've used is to create a small module that modifies my solr query and/or solr results... I actually set my default sorting in that module. Here's a snippet of my code:

function YOURMODULE_apachesolr_query_alter(&$query) {
  //Set the sort default options.  These are different options.  Just choose one!
  $query->setSolrsort('sort_label', 'asc');  // by title
  $query->setSolrsort('ds_created', 'desc');  // by created date
  $query->setSolrsort('score', 'desc');     // by best match

:-) Hope that helps, since the above wasn't quite what you needed...

  • Hi Boriana and thanks for your reply. I had to use the URL "trick" (that works well) but I'm not happy with the result: understanding how to use the custom filters would bring a much more clean solution.
    – Amandil
    Commented Jul 12, 2012 at 11:11
  • Oh, are you talking about using filters in code? Like in a custom module or something? I can probably help with that too if that's what you intended. I just didn't get that from your question... Commented Jul 12, 2012 at 13:00
  • No, I'm talking about the Custom Filter check box that is present in admin/config/search/apachesolr/search-pages/<name of your page>/edit. When you hit the flag an input field appears with the help text "A comma-separated list of lucene filter queries to apply by default". I would like to set the filters there so that the results page is by default filtered by that parameters. I hope I'm more clear now and sorry for my "Italian" English :)
    – Amandil
    Commented Jul 12, 2012 at 14:13
  • Ah, I see. You know, I just tested all the combinations I could think of, and nothing worked. If nobody else responds, I'd just open up an issue ticket with the module asking for an explanation. I had to do that to figure out how to use the fq parameters, and they ammended their documentation: (drupal.org/node/1592860). I did find this ticket asking for some documentation on the custom filters, but it doesn't go into sorting: drupal.org/node/1677076. Sorry I can't help more! Commented Jul 12, 2012 at 15:02
  • Thanks again for your replies and the links. Please, keep me informed if you find a way to sort results via custom query, I'll do the same. Bye.
    – Amandil
    Commented Jul 13, 2012 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.