I have created a ViewsSort plugin that works on a normal view (like taxonomy_term) but not on a view based on Search API : it is not present when I click on "Add sort" in BO. This sort is used to create a custom order of content types, and I use hook_views_data_alter() to provide it to views :

/**
 * Implements hook_views_data_alter().
 */
function mymodule_views_data_alter(array &$data) {

  // works on classic view
  $data['node_field_data']['inspiration_first'] = array(
    'title' => t('Custom search sort in page tags with inspiration first'),
    'group' => t('Search'),
    'help' => t('Sort content types in this order : dossier_inspiration, dossier_conseil, produit.'),
    'sort' => array(
      'field' => 'type',
      'id' => 'inspiration_first',
    ),
  );

  // doesn't work on search api view
  $data['search_api_db_default_search_content_index_content_type']['inspiration_first'] = array(
    'title' => t('Place inspiration first for custom search'),
    'group' => t('Search'),
    'help' => t('Sort content types in this order : dossier_inspiration, dossier_conseil, produit.'),
    'sort' => array(
      'field' => 'value',
      'id' => 'inspiration_first',
    ),
  );

}

Any idea ? Some sorts like Random work also on search api and I've provided the good table, I think (search_api_db_default_search_content_index_content_type).

Go to

Home -> Administration -> Configuration -> Search and metadata -> Search API

& Edit your Index Search. Then your URL will be like below. In my case it's

Content Search

/admin/config/search/search-api/index/content_search/

So I'm using

$data['search_api_index_content_search']['inspiration_first']

I think in ur case it will be

$data['search_api_index_search_content_index']['inspiration_first']

Please share your URL if didn't worked.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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