search_api_elasticsearch.module in Search API Elasticsearch 7.2
Same filename and directory in other branches
Provides an elasticsearch-based service class for the Search API.
File
search_api_elasticsearch.moduleView source
<?php
/**
* @file
* Provides an elasticsearch-based service class for the Search API.
*/
define('SEARCH_API_ELASTICSEARCH_DATE_FORMAT', 'Y-m-d\\TH:i:s.uP');
/**
* Implements hook_entity_presave().
*/
function search_api_elasticsearch_entity_presave($entity, $type) {
if ($type == 'search_api_index') {
if ($entity->is_new) {
SearchApiElasticsearchIndex::setCurrentIndexName($entity);
}
}
}
/**
* Implements hook_menu().
*/
function search_api_elasticsearch_menu() {
$items = [];
return $items;
}
/**
* Implements hook_search_api_service_info().
*/
function search_api_elasticsearch_search_api_service_info() {
$services['search_api_elasticsearch_service'] = array(
'name' => t('Elasticsearch'),
'description' => t('
<p>Index items using a !url_elasticsearch search server.</p>', array(
'!url_elasticsearch' => '<a href="http://www.elasticsearch.org/">' . t('Elasticsearch') . '</a>',
)),
'class' => 'SearchApiElasticsearchService',
);
return $services;
}
/**
* Implements hook_views_api().
*/
function search_api_elasticsearch_views_api() {
return array(
'api' => '3.0',
);
}
/**
* Get server ID by name.
*
* @param string $server_machine_name
*
* @return int
*/
function search_api_elasticsearch_get_server_id_by_name($server_machine_name) {
$query = '';
$result = '';
try {
$query = db_select('search_api_server', 'sas');
$query
->addField('sas', 'id');
$query
->condition('sas.machine_name', $server_machine_name, '=');
$result = $query
->execute()
->fetchAssoc();
} catch (Exception $e) {
watchdog('Search API Elasticsearch', $e
->getMessage(), array(), WATCHDOG_ERROR);
return FALSE;
}
if (isset($result) && !empty($result)) {
return reset($result);
}
else {
return FALSE;
}
}
/**
* Ajax callback.
*
* @param array $form
* @param array $form_state
*
* @return array
*/
function search_api_elasticsearch_ajax_callback($form, &$form_state) {
return $form['options'];
}
/**
* Attach the Ajax attributes.
*
* @param array $form
*/
function search_api_elasticsearch_attach_ajax_callback(&$form) {
$form['options']['#prefix'] = '<div id="elasticsearch-add-index">';
$form['options']['#suffix'] = '</div>';
$form['server']['#ajax'] = array(
'callback' => 'search_api_elasticsearch_ajax_callback',
'wrapper' => 'elasticsearch-add-index',
'method' => 'replace',
'effect' => 'fade',
);
}
/**
* Submit handler
* @param array $form
* @param array $form_state
*/
function search_api_elasticsearch_edit_index_submit(array $form, array &$form_state) {
/*form_state_values_clean($form_state);
$merge_types = array();
$elastic_server_id = search_api_elasticsearch_get_server_id_by_name($form_state['index']->server);
$elastic_server = search_api_server_load($elastic_server_id);
$index = $form_state['index'];
$elastic_server->updateSettings($index, $merge_types);*/
}
/**
* Submit handler
* @param array $form
* @param array $form_state
*/
function search_api_elasticsearch_add_index_submit(array $form, array &$form_state) {
form_state_values_clean($form_state);
}
/**
* Ajax callback for adding more nodes.
*
* @param array $form
* @param array $form_state
*/
function _search_api_elasticsearch_configuration_form_ajax($form, &$form_state) {
unset($form['options']['form']['add_more']);
if (module_exists('search_api_facetapi')) {
unset($form['options']['form']['facet_settings']);
}
return $form['options']['form'];
}
/**
* Ajax callback for remove nodes.
* @param array $form
* @param array $form_state
*/
function _search_api_elasticsearch_configuration_form_remove_ajax($form, &$form_state) {
unset($form['options']['form']['add_more']);
if (module_exists('search_api_facetapi')) {
unset($form['options']['form']['facet_settings']);
}
return $form['options']['form'];
}
/**
* Submit Handler for the configuration form.
*
* @param array $form
* @param array $form_state
*/
function _search_api_elasticsearch_configuration_form_submit_custom($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
/**
* Submit handler on removing elements
*
* @param array $form
* @param array $form_state
*/
function _search_api_elasticsearch_configuration_form_remove_custom($form, &$form_state) {
$form_state['values']['remove_delta'] = 'none';
if (isset($form_state['triggering_element']['#remove_delta'])) {
$form_state['values']['remove_delta'] = $form_state['triggering_element']['#remove_delta'];
}
$form_state['rebuild'] = TRUE;
}
Functions
Name | Description |
---|---|
search_api_elasticsearch_add_index_submit | Submit handler |
search_api_elasticsearch_ajax_callback | Ajax callback. |
search_api_elasticsearch_attach_ajax_callback | Attach the Ajax attributes. |
search_api_elasticsearch_edit_index_submit | Submit handler |
search_api_elasticsearch_entity_presave | Implements hook_entity_presave(). |
search_api_elasticsearch_get_server_id_by_name | Get server ID by name. |
search_api_elasticsearch_menu | Implements hook_menu(). |
search_api_elasticsearch_search_api_service_info | Implements hook_search_api_service_info(). |
search_api_elasticsearch_views_api | Implements hook_views_api(). |
_search_api_elasticsearch_configuration_form_ajax | Ajax callback for adding more nodes. |
_search_api_elasticsearch_configuration_form_remove_ajax | Ajax callback for remove nodes. |
_search_api_elasticsearch_configuration_form_remove_custom | Submit handler on removing elements |
_search_api_elasticsearch_configuration_form_submit_custom | Submit Handler for the configuration form. |
Constants
Name | Description |
---|---|
SEARCH_API_ELASTICSEARCH_DATE_FORMAT | @file Provides an elasticsearch-based service class for the Search API. |