abstract class SearchApiAbstractService in Search API 7
Abstract class with generic implementation of most service methods.
For creating your own service class extending this class, you only need to implement indexItems(), deleteItems() and search() from the SearchApiServiceInterface interface.
Hierarchy
- class \SearchApiAbstractService implements SearchApiServiceInterface
Expanded class hierarchy of SearchApiAbstractService
File
- includes/
service.inc, line 283 - Contains SearchApiServiceInterface and SearchApiAbstractService.
View source
abstract class SearchApiAbstractService implements SearchApiServiceInterface {
/**
* @var SearchApiServer
*/
protected $server;
/**
* Direct reference to the server's $options property.
*
* @var array
*/
protected $options = array();
/**
* Implements SearchApiServiceInterface::__construct().
*
* The default implementation sets $this->server and $this->options.
*/
public function __construct(SearchApiServer $server) {
$this->server = $server;
$this->options =& $server->options;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* Returns an empty form by default.
*/
public function configurationForm(array $form, array &$form_state) {
return array();
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* Does nothing by default.
*/
public function configurationFormValidate(array $form, array &$values, array &$form_state) {
return;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* The default implementation just ensures that additional elements in
* $options, not present in the form, don't get lost at the update.
*/
public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
if (!empty($this->options)) {
$values += $this->options;
}
$this->options = $values;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* The default implementation always returns FALSE.
*/
public function supportsFeature($feature) {
return FALSE;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* The default implementation does a crude output as a definition list, with
* option names taken from the configuration form.
*/
public function viewSettings() {
$output = '';
$form = $form_state = array();
$option_form = $this
->configurationForm($form, $form_state);
$option_names = array();
foreach ($option_form as $key => $element) {
if (isset($element['#title']) && isset($this->options[$key])) {
$option_names[$key] = $element['#title'];
}
}
foreach ($option_names as $key => $name) {
$value = $this->options[$key];
$output .= '<dt>' . check_plain($name) . '</dt>' . "\n";
$output .= '<dd>' . nl2br(check_plain(print_r($value, TRUE))) . '</dd>' . "\n";
}
return $output ? "<dl>\n{$output}</dl>" : '';
}
/**
* Returns additional, service-specific information about this server.
*
* If a service class implements this method and supports the
* "search_api_service_extra" option, this method will be used to add extra
* information to the server's "View" tab.
*
* In the default theme implementation this data will be output in a table
* with two columns along with other, generic information about the server.
*
* @return array
* An array of additional server information, with each piece of information
* being an associative array with the following keys:
* - label: The human-readable label for this data.
* - info: The information, as HTML.
* - status: (optional) The status associated with this information. One of
* "info", "ok", "warning" or "error". Defaults to "info".
*
* @see supportsFeature()
*/
public function getExtraInformation() {
return array();
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* Does nothing, by default.
*/
public function postCreate() {
return;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* The default implementation always returns FALSE.
*/
public function postUpdate() {
return FALSE;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* By default, deletes all indexes from this server.
*/
public function preDelete() {
$indexes = search_api_index_load_multiple(FALSE, array(
'server' => $this->server->machine_name,
));
foreach ($indexes as $index) {
// removeIndex() might throw exceptions, but this method mustn't.
try {
$this
->removeIndex($index);
} catch (SearchApiException $e) {
$variables['%index'] = $index->name;
$variables['%server'] = $this->server->name;
watchdog_exception('search_api', $e, '%type while trying to remove index %index from deleted server %server: !message in %function (line %line of %file).', $variables);
}
}
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* Does nothing, by default.
*/
public function addIndex(SearchApiIndex $index) {
return;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* The default implementation always returns FALSE.
*/
public function fieldsUpdated(SearchApiIndex $index) {
return FALSE;
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* By default, removes all items from that index.
*/
public function removeIndex($index) {
if (is_object($index) && empty($index->read_only)) {
$this
->deleteItems('all', $index);
}
}
/**
* Implements SearchApiServiceInterface::__construct().
*
* The default implementation returns a SearchApiQuery object.
*/
public function query(SearchApiIndex $index, $options = array()) {
return new SearchApiQuery($index, $options);
}
}