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);
    }
}
/**  ?? _solrToExcel_QuerySolrServer()
 *  This function will look at $_GET (and $_POST data (via $_REQUEST)) and build the nessesary
 *  Solr-query to hit the Solr-search-server with, and return Solr's responce.
 */
function _solrToExcel_QuerySolrServer()
{
    $solr = apachesolr_get_solr();
    $solrsort = '';
    $params = unserialize($_POST['params_serialized']);
    $selectedOption = $_POST['dc'];
    if ($selectedOption == 'range') {
        $pageFrom = intval($_POST['rangefrom']);
        $pageTo = intval($_POST['rangeto']);
        $params["start"] = 10 * ($pageFrom - 1);
        $params["rows"] = 10 * ($pageTo - $pageFrom + 1);
    } else {
        if (strpos($selectedOption, '_')) {
            $pageNumber = intval(str_replace('current_', '', $selectedOption));
            $params["start"] = $pageNumber >= 1 ? $pageNumber * 10 : 0;
            $params["rows"] = 10;
        } else {
            $params["start"] = 0;
            $params["rows"] = intval($selectedOption);
        }
    }
    $query1 = apachesolr_drupal_query('apachesolr', $params);
    apachesolr_search_add_boost_params($query1);
    $response = $query1->search();
    return $response;
}
$params['hl'] = TRUE;
$params['hl.fl'] = 'content';
$params['hl.snippets'] = 3;
$params['hl.mergeContigious'] = array(TRUE);
$params['f.content.hl.alternateField'] = array('teaser');
$params['f.content.hl.maxAlternateFieldLength'] = array(256);
$params['qf'] = array('content^40', 'label^5.0', 'tags_h1^5.0', 'tags_h2_h3^3.0', 'tags_h4_h5_h6^2.0', 'tags_inline^1.0', 'taxonomy_names^2.0', 'tos_name^3.0');
$params['facet'] = TRUE;
$params['facet.sort'] = array('count');
$params['facet.mincount'] = 1;
$params['facet.field'] = array('{!ex=bundle}bundle');
$params['f.bundle.facet.limit'] = array(50);
$params['f.bundle.facet.mincount'] = array(1);
$params["start"] = 0;
$params["rows"] = 10;
$query = apachesolr_drupal_query('apachesolr', $params);
apachesolr_search_add_boost_params($query);
$response = $query->search();
$results = $response->response->docs;
if (!empty($_REQUEST['format']) && strcasecmp('csv', $_REQUEST['format']) !== FALSE) {
    ob_clean();
    $out = fopen('php://output', 'w');
    header('Content-Type: text/csv');
    header('Content-Disposition: inline');
    //   Print the results
    $header_done = FALSE;
    foreach ($results as $result_object) {
        $result = (array) $result_object;
        if (!$header_done) {
            $header = array_keys($result);
            fputcsv($out, $header);
Exemplo n.º 4
0
 /**
  * Get an instance of a Drupal_Solr_Query_Interface.
  *
  * This class does not implement Drupal_Solr_Query_Interface, but it provides
  * this method for retrieving and instance of the class.
  *
  * @see apachesolr_Drupal_query().
  * @return 
  *  Instance of Drupal_Solr_Query_Interface.
  */
 public function drupalSolrQuery()
 {
     if (!function_exists('apachesolr_drupal_query')) {
         throw new Exception('Function apachesolr_drupal_query was not found. This does not look like Drupal (Or maybe the apachesolr module is not installed.).');
     }
     return apachesolr_drupal_query($this->query(), $this->filters(), $this->sort(), $this->path(), $this->solr);
 }