Drupal Search API custom search field order

perpetual_dream

am using search api views module to search my apache Solr Search engine. I would like to have a custom order for the returned results. I would like the jq_articles results to appear first, then books, then mydocuments.

How can I have this customer order (with is neither ASC or DESC) for my returned results?

I mean I need something like $query->orderby('jq_articles, 'books', 'mydocuments');

This is how my query_alter looks at the time being:

<?php
function mymodule_search_api_query_alter(SearchApiQueryInterface $query) {
    $filters = &$query->getFilter()->getFilters();
    foreach ($filters as $i => $filter) {
        $condition="";
        $finalfilters=&$filter->getFilters();
        foreach($finalfilters as $z => $singlefilter){
                    if($singlefilter[0]=='type') {
                         $condition=$singlefilter[1];
                         unset($finalfilters[$z]);
                    }
         }
    }
          $filter = $query->createFilter('OR');
switch($condition) {
            case 'journals':
              $filter->condition('type', 'jq_articles');
              break;
            case 'books':
                $filter->condition('type', 'books');
                break;
            case 'mydocuments':
            $filter->condition('type', 'mydocuments');
            default:
            $filter->condition('type', 'mydocuments');
            $filter->condition('type', 'books');
            $filter->condition('type', 'jq_articles');
            break;
}
          $query->filter($filter);
}
?>
Zolyboy

You can do this by adding the following in hook_search_api_query_alter():

$query->sort('jq_articles', 'DESC');

If you want to sort by multiple fields, you should do like this:

$query->sort('field1', 'DESC');
$query->sort('field2', 'ASC');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Drupal Search API custom search field order

From Dev

Drupal Search function in custom module

From Dev

How to move a search input field (filter) in Search API module to different region (Drupal 7)?

From Dev

Custom Search API for deprecated Patent Search API

From Dev

WordPress search filter by custom field

From Dev

CSS drupal search api float elements

From Dev

How to search in PHP using Drupal 7 Search API?

From Dev

Google Custom Search API - Reverse image search

From Dev

ElasticSearch PHP API Search by Field

From Dev

Android and Google Custom Search API

From Dev

Google Custom Search API javascript

From Dev

Search gmail api by custom header

From Dev

Google Custom Search API javascript

From Dev

Add a span before search input field in Drupal 7

From Dev

Custom sort-order in Xquery search options

From Dev

Hibernate full text search custom order by

From Dev

Angular custom text search filter order

From Dev

MYSQL custom query order by search token issue

From Dev

Spring Elastic Search Custom Field names

From Dev

City proximity search drupal

From Dev

Graph Search API order by like fql

From Dev

Google Knowledge Graph Search API @id field

From Dev

Search image on Google images with the new Custom Search API?

From Dev

Hide Search Engine ID for Google Custom Search Element API 2.0

From Dev

Search image on Google images with the new Custom Search API?

From Dev

Drupal 7: Search View with multiple search terms

From Dev

download images with google custom search api

From Dev

GAE Search API: custom snippet length

From Dev

Google Custom Search - Query database/API?