Add hooks to allow query alter, param alter and filter alter

Created on 21 April 2017, over 7 years ago
Updated 12 March 2024, 10 months ago

Hello, i've created a small patch who creates some usefull hooks.
Now you can alter the array that is passed to the connector immediately before the query is executed.

This allows you to add conditions that would be impossible with Basic SearchApiQuery, for example:

function show_search_results_elasticsearch_connector_sort_search_query_alter(&$sort, &$query) {
    if ($query->getSearchId() == 'views_page:es_shows__page_list') {
      $scriptSort['_script'] = [
        'type' => 'string',
        'script' => [
          'lang' => 'painless',
          'inline' => "def n; if(doc['end_value'].value < " . strtotime('today') . "){ n = 0; } else{ n = 1; } return n;",
        ],
        'order' => 'desc'
      ];
      $sort = array_merge($scriptSort, $sort);
    }
  }

I hope it can be useful

Feature request
Status

Needs review

Version

7.0

Component

Code

Created by

🇮🇹Italy csedax90

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024