Is out possible to have a second sort criteria ?
Any idea , thanks

Comments

mkalbere’s picture

I had no time to do that in a clean way, so
in search_api_solr/service.inc ~l 555
Replace

if ($sort) {
      $params['sort'] = implode(', ', $sort);
}

by

if ($sort) {
      $params['sort'] = implode(', ', $sort);
      $params['sort'].=",bs_sticky desc";
    }else{
      $params['sort'].="bs_sticky desc";
    }
dtarc’s picture

I would like to do something like this too. Here's the use case we're looking for:

If no search terms have been entered, sort alphabetically by node title ascending.

If search terms have been entered, sort by relevance descending.

It seems that this module does not yet support this.

Perhaps I will try the same strategy as mkalbere although I would like something cleaner. Does anybody have any suggestions on how to start? Thanks.

Anonymous’s picture

Status: Active » Closed (won't fix)

Ok so these are two different issues.

Issue #1: Sort by X, then sort by Y, then sort by Z (hierarchical sorts) - I have no plans to implement this at the moment, it will add a lot of complexity to the extension. If you really need this, then please go ahead and custom hack into the module like #1 did.

Issue #2: Two default search preference, a) when search terms are present; b) when NO search terms are present.
I feel inclinded to add this feature indeed, but please submit a patch for it and I will consider it for sure.

I have created a separate issue for #2: #1637794: Add default sort for when NO search terms are present, and when they are

Closing this thread for #1, I will not implement that feature.

strykaizer’s picture

I fixxed this in a custom module implementing hook_search_api_query_alter

Note: my 2nd sort is hardcoded, so no need for extra logic for me.

/**
 * Implements hook_search_api_query_alter
 */
function mycustommodule_search_api_query_alter(SearchApiQueryInterface $query) {
  // Add extra default sort on field_type
  $query->sort('field_type', 'asc');
}