function apachesolr_search_mlt_suggestions in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr_search.module \apachesolr_search_mlt_suggestions()
- 6.3 apachesolr_search.module \apachesolr_search_mlt_suggestions()
Performs a moreLikeThis query using the settings and retrieves documents.
Parameters
$settings: An array of settings.
$id: The Solr ID of the document for which you want related content. For a node that is apachesolr_document_id($node->nid)
$solr: The solr environment you want to query against
Return value
An array of response documents, or NULL
2 calls to apachesolr_search_mlt_suggestions()
- apachesolr_search_block_view in ./
apachesolr_search.module - Implements hook_block_view().
- DrupalApacheSolrNodeAccess::testIndexing in apachesolr_access/
tests/ apachesolr_access.test - Tests indexing and check if it adds the correct grants for those specific users
File
- ./
apachesolr_search.module, line 675 - Provides a content search implementation for node content for use with the Apache Solr search application.
Code
function apachesolr_search_mlt_suggestions($settings, $id, $solr = NULL, $context = array()) {
try {
$fields = array(
'mlt_mintf' => 'mlt.mintf',
'mlt_mindf' => 'mlt.mindf',
'mlt_minwl' => 'mlt.minwl',
'mlt_maxwl' => 'mlt.maxwl',
'mlt_maxqt' => 'mlt.maxqt',
'mlt_boost' => 'mlt.boost',
'mlt_qf' => 'mlt.qf',
);
$params = array(
'q' => 'id:' . $id,
'qt' => 'mlt',
'fl' => array(
'entity_id',
'entity_type',
'label',
'path',
'url',
),
'mlt.fl' => $settings['mlt_fl'],
'start' => 0,
'rows' => $settings['num_results'],
);
// We can optionally specify a Solr object.
$query = apachesolr_drupal_query('apachesolr_mlt', $params, '', '', $solr, $context);
foreach ($fields as $form_key => $name) {
if (!empty($settings[$form_key])) {
$query
->addParam($name, $settings[$form_key]);
}
}
$type_filters = array();
if (is_array($settings['mlt_type_filters']) && !empty($settings['mlt_type_filters'])) {
$query
->addFilter('bundle', '(' . implode(' OR ', $settings['mlt_type_filters']) . ') ');
}
if (!empty($settings['mlt_custom_filters'])) {
$custom_filters = explode(',', $settings['mlt_custom_filters']);
foreach ($custom_filters as $custom_filter) {
list($filter_index, $filter_value) = explode(':', $custom_filter, 2);
$query
->addFilter($filter_index, $filter_value);
}
}
// This hook allows modules to modify the query object.
drupal_alter('apachesolr_query', $query);
if ($query->abort_search) {
return NULL;
}
$response = $query
->search();
if (isset($response->response->docs)) {
return (array) $response->response->docs;
}
} catch (Exception $e) {
apachesolr_log_exception($solr
->getId(), $e);
}
}