/** * Alter the search results before they are returned. * * @param array $results * The results returned by the server, which may be altered. The data * structure is the same as returned by SearchApiQueryInterface::execute(). * @param SearchApiQueryInterface $query * The search query that was executed. */ function hook_search_api_results_alter(array &$results, SearchApiQueryInterface $query) { if ($query->getOption('search id') == 'search_api_views:my_search_view:page') { // Log the number of results. $vars = array('@keys' => $query->getOriginalKeys(), '@num' => $results['result count']); watchdog('my_module', 'Search view with query "@keys" had @num results.', $vars, WATCHDOG_DEBUG); } }
/** * 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; } } }