View source
<?php
include_once 'panopoly_search.features.inc';
function panopoly_search_ctools_plugin_directory($module, $plugin) {
return 'plugins/' . $plugin;
}
function panopoly_search_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_form' || $form_id == 'search_block_form' || $form_id == 'search_theme_form') {
$form['#submit'][] = 'panopoly_search_all_form_submit';
if (!empty($form['basic']['keys'])) {
$form['basic']['keys']['#size'] = '';
}
}
}
function panopoly_search_all_form_submit($form, &$form_state) {
if (!isset($form_state['values']['keys'])) {
$keys = trim($form_state['values'][$form['#form_id']]);
}
else {
$keys = trim($form_state['values']['keys']);
}
$module = !empty($form_state['values']['module']) ? $form_state['values']['module'] : 'site';
$module = $module === 'node' ? 'site' : $module;
$form_state['redirect'] = array(
'search/' . $module . '/' . $keys,
);
}
function panopoly_search_enable_solr() {
require_once drupal_get_path('module', 'search_api') . '/search_api.admin.inc';
$solr_server = search_api_server_load('solr_server');
$solr_server
->update(array(
'enabled' => 1,
));
$solr_index = search_api_index_load('node_index');
$solr_index
->update(array(
'server' => 'solr_server',
'enabled' => 1,
));
$solr_index
->clear();
$solr_index
->reindex();
}
function panopoly_search_default_search_api_server_alter(&$items) {
if (isset($items['solr_server'])) {
if ($solr_server = search_api_server_load('solr_server')) {
$items['solr_server']->options = $solr_server->options;
$items['solr_server']->enabled = $solr_server->enabled;
}
}
}
function panopoly_search_default_search_api_index_alter(&$items) {
if (isset($items['node_index'])) {
if ($solr_index = search_api_index_load('node_index')) {
$items['node_index']->server = $solr_index->server;
$items['node_index']->enabled = $solr_index->enabled;
}
}
}
function panopoly_search_form_pantheon_apachesolr_post_schema_form_alter(&$form, &$form_state) {
$form['#submit'][] = 'panopoly_search_pantheon_apachesolr_post_schema_form_submit';
}
function panopoly_search_pantheon_apachesolr_post_schema_form_submit($form, &$form_state) {
if (variable_get('pantheon_apachesolr_schema', FALSE)) {
panopoly_search_enable_solr();
}
}
function panopoly_search_modules_enabled($modules) {
if (in_array('panopoly_search', $modules) && variable_get('pantheon_tier', FALSE) && variable_get('panopoly_search_enable_pantheon_apachesolr', TRUE) && module_enable(array(
'pantheon_apachesolr',
))) {
drupal_get_messages('status');
$schema_uri = drupal_get_path('module', 'search_api_solr') . '/solr-conf/3.x/schema.xml';
$response = pantheon_apachesolr_post_schema_exec($schema_uri);
if ($response != NULL) {
panopoly_search_enable_solr();
}
}
}
function panopoly_search_search_api_query_alter($query) {
$keys = $query
->getOriginalKeys();
if (empty($keys)) {
return;
}
$type = $query
->getIndex()
->getEntityType();
$search_info = search_get_info();
$type_title = $type;
if (isset($search_info[$type])) {
$type_title = $search_info[$type]['title'];
}
$link = NULL;
if ($type == 'node') {
$link = l(t('results'), 'search/site/' . $keys);
}
watchdog('search', 'Searched %type for %keys.', array(
'%keys' => $keys,
'%type' => $type_title,
), WATCHDOG_NOTICE, $link);
}