class SearchApiAcquiaSearchService in Acquia Search for Search API 7
Same name and namespace in other branches
- 7.2 includes/SearchApiAcquiaSearchService.php \SearchApiAcquiaSearchService
Search API service class for Acquia Search.
Hierarchy
- class \SearchApiAbstractService implements SearchApiServiceInterface
- class \SearchApiSolrService
- class \SearchApiAcquiaSearchService
- class \SearchApiSolrService
Expanded class hierarchy of SearchApiAcquiaSearchService
1 string reference to 'SearchApiAcquiaSearchService'
File
- includes/
SearchApiAcquiaSearchService.php, line 11 - Contains SearchApiAcquiaSearchService.
View source
class SearchApiAcquiaSearchService extends SearchApiSolrService {
/**
* Overrides SearchApiSolrService::connect().
*/
protected function connect() {
if (!$this->solr) {
if (!class_exists('Apache_Solr_Service')) {
throw new Exception(t('SolrPhpClient library not found! Please follow the instructions in search_api_solr/INSTALL.txt for installing the Solr search module.'));
}
// Set our special overrides if applicable
$this
->setConnectionOptions();
// Set the solr connection object.
$this->solr = new SearchApiAcquiaSearchConnection($this->options);
}
}
/**
* View this server's settings.
*/
public function viewSettings() {
$output = '';
// Set our special overrides if applicable
$this
->setConnectionOptions();
$options = $this->options;
$url = $options['scheme'] . '://' . $options['host'] . ':' . $options['port'] . $options['path'];
$output .= "<dl>\n <dt>";
$output .= t('Acquia Search Server');
$output .= "</dt>\n <dd>";
$output .= $url;
$output .= '</dd>';
if ($options['http_user']) {
$output .= "\n <dt>";
$output .= t('Basic HTTP authentication');
$output .= "</dt>\n <dd>";
$output .= t('Username: @user', array(
'@user' => $options['http_user'],
));
$output .= "</dd>\n <dd>";
$output .= t('Password: @pass', array(
'@pass' => str_repeat('*', strlen($options['http_pass'])),
));
$output .= '</dd>';
}
$output .= "\n</dl>";
return $output;
}
/**
* Set some special overrides for Acquia Search
*/
public function setConnectionOptions() {
// Modify connection details live on every connect so we do not need to
// resave the server details if we make modifications in settings.php.
$identifier = acquia_agent_settings('acquia_identifier');
$subscription = acquia_agent_settings('acquia_subscription_data');
// Get our override if we have one. Otherwise use the default.
$search_host = variable_get('acquia_search_host', 'search.acquia.com');
if (!empty($subscription['heartbeat_data']['search_service_colony'])) {
$search_host = $subscription['heartbeat_data']['search_service_colony'];
}
// Get our solr path
$search_path = variable_get('acquia_search_path', '/solr/' . $identifier);
$this->options['host'] = $search_host;
$this->options['path'] = $search_path;
// We can also have overrides per server setting.
// Apply the overrides in the "search_api_acquia_overrides" variable.
$name = $this->server->machine_name;
$overrides = variable_get('search_api_acquia_overrides', array());
if (isset($overrides[$name]) && is_array($overrides[$name])) {
$this->options = array_merge($this->options, $overrides[$name]);
}
}
/**
* Overrides SearchApiSolrService::configurationForm().
*
* Populates the Solr configs with Acquia Search Information.
*/
public function configurationForm(array $form, array &$form_state) {
$form = parent::configurationForm($form, $form_state);
// Set our special overrides if applicable
$this
->setConnectionOptions();
$options = $this->options += array(
'edismax' => 0,
'host' => $search_host,
'port' => '80',
'path' => variable_get('acquia_search_path', '/solr/' . $identifier),
'modify_acquia_connection' => FALSE,
'scheme' => 'http',
);
// HTTP authentication is not needed since Acquia Search uses an HMAC
// authentication mechanism.
$form['http']['#access'] = FALSE;
$form['edismax'] = array(
'#type' => 'checkbox',
'#title' => t('Always allow advanced syntax for Acquia Search'),
'#default_value' => $options['edismax'],
'#description' => t('If enabled, all Acquia Search keyword searches may use advanced <a href="@url">Lucene syntax</a> such as wildcard searches, fuzzy searches, proximity searches, boolean operators and more via the Extended Dismax parser. If not enabled, this syntax wll only be used when needed to enable wildcard searches.', array(
'@url' => 'http://lucene.apache.org/java/2_9_3/queryparsersyntax.html',
)),
'#weight' => -30,
);
$form['modify_acquia_connection'] = array(
'#type' => 'checkbox',
'#title' => 'Modify Acquia Search Connection Parameters',
'#default_value' => $options['modify_acquia_connection'],
'#description' => t('Only check this box if you are absolutely certain about what you are doing. Any misconfigurations will most likely break your site\'s connection to Acquia Search.'),
'#weight' => -20,
);
// Disable any port configuration option as Acquia will always be in
//control of those ports
$form['port']['#access'] = FALSE;
// Disable the http method that is selected as Acquia will always be https
// unless ACQUIA_DEVELOPMENT_NOSSL was set.
$form['scheme']['#access'] = FALSE;
$form['clean_ids_form']['#weight'] = 10;
// Re-sets defaults with Acquia information.
$form['host']['#default_value'] = $options['host'];
$form['path']['#default_value'] = $options['path'];
// Only display fields if we are modifying the connection parameters to the
// Acquia Search service.
$states = array(
'visible' => array(
':input[name="options[form][modify_acquia_connection]"]' => array(
'checked' => TRUE,
),
),
);
$form['host']['#states'] = $states;
$form['path']['#states'] = $states;
if ($this->options['scheme'] == 'https') {
$this->options['port'] = '443';
}
else {
$this->options['port'] = '80';
}
// We cannot connect directly to the Solr instance, so don't make it a link.
if (isset($form['server_description'])) {
$url = $this->options['scheme'] . '://' . $this->options['host'] . ':' . $this->options['port'] . $this->options['path'];
$form['server_description'] = array(
'#type' => 'item',
'#title' => t('Acquia Search URI'),
'#description' => check_plain($url),
'#weight' => -40,
);
}
return $form;
}
/**
* Overrides SearchApiSolrService::configurationFormValidate().
*
* Forces defaults if the override option is unchecked.
*
* @see http://drupal.org/node/1852692
*/
public function configurationFormValidate(array $form, array &$values, array &$form_state) {
$modified = !empty($form_state['values']['options']['form']['modify_acquia_connection']);
if (!$modified) {
// Set our special overrides if applicable
$this
->setConnectionOptions();
form_set_value($form['host'], $this->options['host'], $form_state);
form_set_value($form['port'], $this->options['port'], $form_state);
form_set_value($form['path'], $this->options['path'], $form_state);
}
parent::configurationFormValidate($form, $values, $form_state);
}
/**
* Overrides SearchApiSolrService::preQuery().
*
* Sets the eDisMax parameters if certain conditions are met, adds the default
* parameters that are usually set in Search API's solrconfig.xml file.
*/
protected function preQuery(array &$call_args, SearchApiQueryInterface $query) {
$params =& $call_args['params'];
// Bails if this is a 'mlt' query or something else custom.
if (!empty($params['qt']) || !empty($params['defType'])) {
return;
}
// The Search API module adds default "fl" parameters in solrconfig.xml
// that are not present in Acquia Search's solrconfig.xml file. Add them
// and others here as a backwards compatible solution.
// @see http://drupal.org/node/1619770
$params += array(
'echoParams' => 'none',
'fl' => 'item_id,score',
'q.op' => 'AND',
'q.alt' => '*:*',
'spellcheck' => 'false',
'spellcheck.onlyMorePopular' => 'true',
'spellcheck.extendedResults' => 'false',
'spellcheck.count' => '1',
'hl' => 'false',
'hl.fl' => 'spell',
'hl.simple.pre' => '[HIGHLIGHT]',
'hl.simple.post' => '[/HIGHLIGHT]',
'hl.snippets' => '3',
'hl.fragsize' => '70',
'hl.mergeContiguous' => 'true',
);
// Set the qt to eDisMax if we have keywords and either the configuration
// is set to always use eDisMax or the keys contain a wildcard (* or ?).
$keys = $query
->getOriginalKeys();
if ($keys && (($wildcard = preg_match('/\\S+[*?]/', $keys)) || $this->options['edismax'])) {
$params['defType'] = 'edismax';
if ($wildcard) {
// Converts keys to lower case, reset keys in query and replaces param.
$new_keys = preg_replace_callback('/(\\S+[*?]\\S*)/', array(
$this,
'toLower',
), $keys);
$query
->keys($new_keys);
$call_args['query'] = $new_keys;
}
}
}
/**
* Convert to lower-case any keywords containing a wildcard.
*
* @see _acquia_search_lower()
*/
public function toLower($matches) {
return drupal_strtolower($matches[1]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiAbstractService:: |
protected | property | Direct reference to the server's $options property. | |
SearchApiAbstractService:: |
protected | property | ||
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
|
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
|
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
1 |
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
|
SearchApiAbstractService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiServiceInterface:: |
|
SearchApiAcquiaSearchService:: |
public | function |
Overrides SearchApiSolrService::configurationForm(). Overrides SearchApiSolrService:: |
|
SearchApiAcquiaSearchService:: |
public | function |
Overrides SearchApiSolrService::configurationFormValidate(). Overrides SearchApiSolrService:: |
|
SearchApiAcquiaSearchService:: |
protected | function |
Overrides SearchApiSolrService::connect(). Overrides SearchApiSolrService:: |
|
SearchApiAcquiaSearchService:: |
protected | function |
Overrides SearchApiSolrService::preQuery(). Overrides SearchApiSolrService:: |
|
SearchApiAcquiaSearchService:: |
public | function | Set some special overrides for Acquia Search | |
SearchApiAcquiaSearchService:: |
public | function | Convert to lower-case any keywords containing a wildcard. | |
SearchApiAcquiaSearchService:: |
public | function |
View this server's settings. Overrides SearchApiSolrService:: |
|
SearchApiSolrService:: |
protected | property | Saves whether a commit operation was already scheduled for this server. | |
SearchApiSolrService:: |
protected | property | The connection class used by this service. | |
SearchApiSolrService:: |
protected | property | Static cache for getFieldNames(). | |
SearchApiSolrService:: |
protected | property | Metadata describing fields on the Solr/Lucene index. | |
SearchApiSolrService:: |
protected | property | Request handler to use for this search query. | |
SearchApiSolrService:: |
protected | property | A connection to the Solr server. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Helper method for indexing. | |
SearchApiSolrService:: |
protected | function | Applies custom modifications to indexed Solr documents. | |
SearchApiSolrService:: |
public | function | Sends a commit command to the Solr server. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Transforms a query filter into a flat array of Solr filter queries, using the field names in $fields. | |
SearchApiSolrService:: |
protected | function | Create a single search query string according to the given field, value and operator. | |
SearchApiSolrService:: |
public | function | Creates an ID used as the unique identifier at the Solr server. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::deleteItems(). Overrides SearchApiServiceInterface:: |
|
SearchApiSolrService:: |
protected | function | Extract facets from a Solr response. | |
SearchApiSolrService:: |
protected | function | Extracts short snippets with highlighting from highlighted field values. | |
SearchApiSolrService:: |
protected | function | Extract results from a Solr response. | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Flatten a keys array into a single search string. | |
SearchApiSolrService:: |
protected | function | Format a value for filtering on a field of a specific type. | |
SearchApiSolrService:: |
protected | function | Changes highlighting tags from our custom, HTML-safe ones to HTML. | |
SearchApiSolrService:: |
public | function | ||
SearchApiSolrService:: |
public | function | Gets the Solr connection class used by this service. | |
SearchApiSolrService:: |
protected | function | Extract and format highlighting information for a specific item from a Solr response. | |
SearchApiSolrService:: |
public | function |
Returns additional, service-specific information about this server. Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | Helper method for creating the facet field parameters. | |
SearchApiSolrService:: |
public | function | Create a list of all indexed field names mapped to their Solr field names. | |
SearchApiSolrService:: |
public | function | Get metadata about fields in the Solr/Lucene index. | |
SearchApiSolrService:: |
public | function | Retrieves a config file or file list from the Solr server. | |
SearchApiSolrService:: |
protected | function | Returns the prefix and suffix for highlighting matches in the excerpt. | |
SearchApiSolrService:: |
protected | function | Helper method for creating the highlighting parameters. | |
SearchApiSolrService:: |
protected | function | Prefixes an index ID as configured. | |
SearchApiSolrService:: |
protected | function | Retrieves the effective fulltext fields from the query. | |
SearchApiSolrService:: |
public | function | Returns a link to the Solr server, if the necessary options are set. | |
SearchApiSolrService:: |
public | function | Gets the currently used Solr connection object. | |
SearchApiSolrService:: |
public | function |
Indexes the specified items. Overrides SearchApiServiceInterface:: |
|
SearchApiSolrService:: |
public | function | Ping the Solr server to tell whether it can be accessed. | |
SearchApiSolrService:: |
protected | function | Empty method to allow subclasses to apply custom changes before search results are returned. | |
SearchApiSolrService:: |
public | function | Implements SearchApiMultiServiceInterface::queryMultiple(). | |
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |
|
SearchApiSolrService:: |
protected | function | ||
SearchApiSolrService:: |
protected | function | Sanitizes a highlighted field value. | |
SearchApiSolrService:: |
public | function | Schedules a commit operation for this server. | |
SearchApiSolrService:: |
public | function |
Executes a search on the server represented by this object. Overrides SearchApiServiceInterface:: |
|
SearchApiSolrService:: |
public | function | Implements SearchApiMultiServiceInterface::searchMultiple(). | |
SearchApiSolrService:: |
public | function | Sets the Solr connection class used by this service. | |
SearchApiSolrService:: |
protected | function | Sets the request handler. | |
SearchApiSolrService:: |
constant | The date format that Solr uses, in PHP date() syntax. | ||
SearchApiSolrService:: |
public | function |
Implements SearchApiServiceInterface::__construct(). Overrides SearchApiAbstractService:: |