Hi,

I've put together a small module that:

1. Implements hook_apachesolr_prepare_query ( adds new default sort to query )
2. Provides an admin settings form to select default sort.

That allows users to select the default sort for search results.

It creates a menu tab at admin/settings/apachesolr/sort for configuration.

module tarball attached, will need tar_.gz extension changed to tar.gz to extract.

DT

P.S I actually developed this for the D5 version of apachesolr - tested and working. I've re-factored for D6 but will need a quick test - thanks.

Comments

davidwhthomas’s picture

StatusFileSize
new20.18 KB

Attaching a screenshot of admin settings form.
DT

pwolanin’s picture

So does this sort of functionality belong in the already-complex admin interface of the main module, or shoudl this code go into the online docs as a reference?

davidwhthomas’s picture

I'd suggest it fits best as an apachesolr/contrib module.

Users can install if they want configurable default sort functionality.

Sort settings, as part of a search module's configuration, seems intuitive to me so I can't see a problem with keeping it as a tab on the main config page.

Would be interested to hear what other people think too though.

DT

jpmckinney’s picture

I'm in favor of putting this in apachesolr_search.module. The admin page needs some love, but I wouldn't say it's irrecoverably complex. I'm committing a first part of this, which makes setting a default sort much easier.

http://drupal.org/cvs?commit=359052

jpmckinney’s picture

Title: Apachesolr_sort - contrib module for setting default sort » Add ability to control default sort

See #590706: Adding 'Default sorting' setting for a preferable way to set the default sort than to add settings to settings/apachesolr/settings.

francewhoa’s picture

Status: Needs work » Needs review

Subscribing

Note to self: Expected similar result #590706: Adding 'Default sorting' setting

davidwhthomas’s picture

OK, I'll look at creating a patch to put the settings in the sort block edit page, rather than the menu callback.

pwolanin’s picture

Is the remainder here a "won't fix"?

pwolanin’s picture

Status: Needs review » Needs work
halstead’s picture

Status: Needs review » Needs work

We are using this with a minor fix in hook menu. I'm interested in working on this.

dalin’s picture

@jpmckinney and @Francewhoa #590706: Adding 'Default sorting' setting will not work if the site does not use the sort block. I think the method that this issue implements is the better way to go.

davidtrainer’s picture

I have a site that needs this functionality; will install and post results. I do prefer this approach to #590706: Adding 'Default sorting' setting. I did not intuitively expect to find the setting on the block configuration page.

jpmckinney’s picture

Category: feature » support
Status: Needs work » Fixed

As a feature request this is wontfix, as default sort can be controlled by implementing hook_apachesolr_prepare_query.

davidwhthomas’s picture

As a feature request this is wontfix, as default sort can be controlled by implementing hook_apachesolr_prepare_query.

Fair enough, but I presume most Drupal users don't know how to program hook_apachesolr_prepare_query.

DT

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

davidwhthomas’s picture

Just a note on this one, if anyone is looking to set default sort order to created date desc in apachesolr D7

You can use this:

<?php
/**
 * Implements hook_apachesolr_prepare_query().
 */
function MYMODULE_apachesolr_query_prepare($query, $caller) {
  // If no manual sort set in querystring, set default sort to created desc
  if (!isset($_GET['solrsort'])) {
    $query->setSolrSort('ds_created', 'desc');
  }
}
?>

HTH,

DT

__cj’s picture

Please note the code is #16 will prevent the Relevancy sort from being used.

I've put in a patch to allow you to change the default sort order.
https://drupal.org/node/2154583

Chris.