function solrmlt_suggestions($block_id, $nid) { try { $solr = apachesolr_get_solr(); $fields = array('mlt.mintf', 'mlt.mindf', 'mlt.minwl', 'mlt.maxwl', 'mlt.maxqt', 'mlt.boost', 'mlt.qf'); $block = apachesolr_mlt_load_block($block_id); $params = array('qt' => 'mlt', 'fl' => 'nid,title,url', 'mlt.fl' => implode(',', $block['mlt_fl'])); foreach ($fields as $field) { $drupal_fieldname = str_replace('.', '_', $field); if (!empty($block[$drupal_fieldname])) { $params[$field] = check_plain($block[$drupal_fieldname]); } } $query = apachesolr_drupal_query('id:' . apachesolr_document_id($nid)); // 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, $block['num_results'], $params); if ($response->response) { $docs = (array) end($response->response); } return $docs; } catch (Exception $e) { watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR); } }
/** * Implements Drupal_SolrDevel_Adapter::analyzeQuery(). */ public function analyzeQuery($keys, $page_id, $entity_id, $entity_type) { $search_page = apachesolr_search_page_load($page_id); $conditions = apachesolr_search_conditions_default($search_page); $solr = apachesolr_get_solr($search_page->env_id); // Sets default parameters. $params = array('q' => $keys, 'fq' => isset($conditions['fq']) ? $conditions['fq'] : array(), 'rows' => 1); $params['fq'][] = 'id:' . apachesolr_document_id($entity_id, $entity_type); $results = apachesolr_search_run('apachesolr', $params, '', '', 0, $solr); return isset($results[0]) ? $results[0] : array(); }