You are here

function apachesolr_mlt_suggestions in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 apachesolr.module \apachesolr_mlt_suggestions()
  2. 5 contrib/apachesolr_mlt/apachesolr_mlt.module \apachesolr_mlt_suggestions()
  3. 6.2 apachesolr.module \apachesolr_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)

Return value

An array of response documents, or NULL

1 call to apachesolr_mlt_suggestions()
apachesolr_block in ./apachesolr.module
Implementation of hook_block().

File

./apachesolr.module, line 1660
Integration with the Apache Solr search application.

Code

function apachesolr_mlt_suggestions($settings, $id) {
  try {
    $solr = apachesolr_get_solr();
    $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(
      'qt' => 'mlt',
      'fl' => 'nid,title,path,url',
      'mlt.fl' => implode(',', $settings['mlt_fl']),
    );
    foreach ($fields as $form_key => $name) {
      if (!empty($settings[$form_key])) {
        $params[$name] = $settings[$form_key];
      }
    }
    $query = apachesolr_drupal_query('id:' . $id);

    // This hook allows modules to modify the query and params objects.
    apachesolr_modify_query($query, $params, 'apachesolr_mlt');
    if (empty($query)) {
      return;
    }
    $response = $solr
      ->search($query
      ->get_query_basic(), 0, $settings['num_results'], $params);
    if ($response->response) {
      $docs = (array) end($response->response);
      return $docs;
    }
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);
  }
}