I know that this module is going to be made defunct with the arrival of views 3 and apachesolr 2, but we needed some extra features for a site we built.

This patch allows the panels admin to choose the number of results they list to show per page.

Comments

steven jones’s picture

If this gets committed, it would be good to get an honorable mention of the company that sponsored this work on the project page:
FreshNetworks - http://www.freshnetworks.com/
This is not a requirement on committing the patch, however.

ximo’s picture

Assigned: Unassigned » ximo
StatusFileSize
new2.33 KB
new1.21 KB

This would be a nice feature, but I'm not sure I would want to alter the $GLOBALS array like that.

You can actually achieve the same thing by implementing hook_apachesolr_modify_query():

function hook_apachesolr_modify_query(&$query, &$params, $caller) {
  if ($on_my_search_page) {
    $params['rows'] = 3;
  }
}

I tried implementing that in Solr Panels (see second attachment), and while it did change the number of rows, the pager wouldn't keep up. Turned out to be a bug in the Apache Solr module, which was easy to fix (see first attachment). I'll leave it at that for now, but feel free to take it to the Apache Solr module's issue queue if you want to pursue it further.

kmadel’s picture

I was actually interested in adding more params than just the rows parameter, plus I wanted to have better integration with Apache Solr Autocomplete. I wanted to avoid my own custom hook_apachesolr_modify_query() as I wanted to have the UI based configuration that can be made available in Panels. Specifically, in addition to the rows parameter, I wanted to override the QF (query fields) parameter on a panel page by panel page basis (and more importantly, pass those parameters to Solr Autocomplete, but that is another issue). No doubt this is somewhat advanced configuration, but not much more advanced than specifying the Filter.

So, I may have a filter set up as 'type:bio tid:21', but then I would also like to specify the query fields for weight purposes but also to be utilized by Autocomplete, so I would like to add 'sort_ss_field_sir_name^10 ss_field_sir_name^10 sort_ss_field_given_name^5 ss_field_given_name^5 ss_sir_name_letter^5' as it is a list of persons that is being searched, and I only want to search against names. I would love to be able to do this all in one place. So, rather than having an apachesolr_panels_apachesolr_modify_query, and pulling stuff out of $_apachesolr_panels_conf, why not just forego calling apachesolr_search_execute() (which does not allow passing in additional parameters like rows or qf -- by the way, the Apache Solr Autocomplete goes even lower level and calls $solr->search to execute their autocomplete search), and basically create your own version of that function that then calls apachesolr_do_query() - thus giving you complete control over $params. Here is an example of what it could look like (and I would be happy to submit a patch if you are interested):

/**
 * Execute a Solr search.
 *
 * Using hook_search() would make this module a first-class search module
 * alongside Apache Solr Search, which we don't want. Instead, we execute the
 * search directly and imitate what the core Search module does.
 *
 * @see search_data()
 */
function apachesolr_panels_search_execute($search) {
  // Store information about the search for use in other panes.
  apachesolr_panels_static_search_cache($search);

  $results = NULL;
  try {
    $caller = 'apachesolr_search';
    //$search['params'] were populated in apachesolr_panels_apachesolr_result_content_type_render()
    $params = $search['params'];
    // This is the object that knows about the query coming from the user.
    $query = apachesolr_drupal_query($search['keys'], $search['filters'], $search['sort'], $search['path']);
    if (empty($query)) {
      throw new Exception(t('Could not construct a Solr query in function apachesolr_search_search()'));
    }
  
    $params += apachesolr_search_basic_params($query);
    if ($keys) {
      $params += apachesolr_search_highlighting_params($query);
      $params += apachesolr_search_spellcheck_params($query);
    }
    else {
      // No highlighting, use the teaser as a snippet.
      $params['fl'] .= ',teaser';
    }
    if (module_exists('upload')) {
      $params['fl'] .= ',is_upload_count';
    }
    apachesolr_search_add_facet_params($params, $query);
    apachesolr_search_add_boost_params($params, $query, apachesolr_get_solr());
  
    list($final_query, $response) = apachesolr_do_query($caller, $query, $params, $page);
    apachesolr_has_searched(TRUE);
    // Add search terms and filters onto the breadcrumb.
    // We use the original $query to avoid exposing, for example, nodeaccess
    // filters in the breadcrumb.
    drupal_set_breadcrumb(array_merge(menu_get_active_breadcrumb(), $query->get_breadcrumb()));
    $results = apachesolr_search_process_response($response, $final_query, $params);
  }
  catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
    apachesolr_failure(t('Solr search'), $search['keys']);
  }

  // Imitate search_data() to present the results as Apache Solr Search would.
  if (is_array($results) && count($results)) {
    if (module_hook('apachesolr_search', 'search_page')) {
      return module_invoke('apachesolr_search', 'search_page', $results);
    }
    else {
      return theme('search_results', $results, 'apachesolr_search');
    }
  }
}
David_Rothstein’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
StatusFileSize
new2.39 KB

Here's a patch for Drupal 7.

ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #4 looks good to me. I note that it's almost identical to a patch submitted to a duplicate issue, http://drupal.org/node/1570598 and is pretty core functionality.

It would be great if we could get this committed, as the patch conflicts with the only other Apache Solr Panels issue that I need fixed, http://drupal.org/node/1708290 . I'm happy to create a new patch for that one to resolve the conflict.

acbramley’s picture

Hi, sorry I have been so absent from the issue queue, I will test this today and hopefully get it committed :)

acbramley’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Closing as duplicate of http://drupal.org/node/1708290 as the patch from there has been committed