function apachesolr_search_run in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr_search.module \apachesolr_search_run()
- 6.3 apachesolr_search.module \apachesolr_search_run()
Execute a search results based on keyword, filter, and sort strings.
Parameters
$name:
$params: Array - 'q' is the keywords to search.
$solrsort:
$base_path: For constructing filter and sort links. Leave empty unless the links need to point somewhere other than the base path of the current request.
integer $page: For pagination.
DrupalApacheSolrServiceInterface $solr: The solr server resource to execute the search on.
Return value
array The returned search results.
Throws
Exception
2 calls to apachesolr_search_run()
- apachesolr_search_search_results in ./
apachesolr_search.module - Executes search depending on the conditions given. See apachesolr_search.pages.inc for another use of this function
- DrupalSolrOfflineSearchPagesWebTestCase::testNewAndRemoveSearchPage in tests/
apachesolr_base.test - Asserts that we can edit a search environment
File
- ./
apachesolr_search.module, line 1097 - Provides a content search implementation for node content for use with the Apache Solr search application.
Code
function apachesolr_search_run($name, array $params = array(), $solrsort = '', $base_path = '', $page = 0, DrupalApacheSolrServiceInterface $solr = NULL, $context = array()) {
// Merge the default params into the params sent in.
$params += apachesolr_search_basic_params();
// This is the object that knows about the query coming from the user.
$query = apachesolr_drupal_query($name, $params, $solrsort, $base_path, $solr, $context);
if ($query
->getParam('q')) {
apachesolr_search_add_spellcheck_params($query);
}
// Add the paging parameters
$query->page = $page;
apachesolr_search_add_boost_params($query);
if ($query
->getParam('q')) {
apachesolr_search_highlighting_params($query);
if (!$query
->getParam('hl.fl')) {
$qf = array();
foreach ($query
->getParam('qf') as $field) {
// Truncate off any boost so we get the simple field name.
$parts = explode('^', $field, 2);
$qf[$parts[0]] = TRUE;
}
foreach (array(
'content',
'ts_comments',
) as $field) {
if (isset($qf[$field])) {
$query
->addParam('hl.fl', $field);
}
}
}
}
else {
// No highlighting, use the teaser as a snippet.
$query
->addParam('fl', 'teaser');
}
list($final_query, $response) = apachesolr_do_query($query);
$env_id = $query
->solr('getId');
apachesolr_has_searched($env_id, TRUE);
if (NULL === $final_query) {
return $response;
}
$process_response_callback = apachesolr_environment_variable_get($env_id, 'process_response_callback', 'apachesolr_search_process_response');
if (function_exists($process_response_callback)) {
return call_user_func($process_response_callback, $response, $final_query);
}
else {
return apachesolr_search_process_response($response, $final_query);
}
}