diff --git a/Solr_Base_Query.php b/Solr_Base_Query.php index 6671d5a..dacd7ca 100644 --- a/Solr_Base_Query.php +++ b/Solr_Base_Query.php @@ -268,6 +268,9 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa // The array keys must always be real Solr index fields. protected $available_sorts; + // The search page id. + protected $page_id; + /** * The query name is used to construct a searcher string. Mostly the * environment id @@ -299,8 +302,11 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa * * @param $base_path * The search base path (without the keywords) for this query, without trailing slash. + * + * @param $page_id + * The search page id. */ - function __construct($name, $solr, array $params = array(), $sortstring = '', $base_path = '') { + function __construct($name, $solr, array $params = array(), $sortstring = '', $base_path = '', $page_id = '') { parent::__construct(); $this->name = $name; $this->solr = $solr; @@ -309,6 +315,7 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa $this->sortstring = trim($sortstring); $this->parseSortString(); $this->base_path = $base_path; + $this->page_id = $page_id; } protected function defaultSorts() { @@ -335,6 +342,13 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa return $this->name . '@' . $this->solr->getId(); } + /** + * Get search page id. + */ + public function getSearchPageId() { + return $this->page_id; + } + protected $single_value_params = array( 'q' => TRUE, // http://wiki.apache.org/solr/SearchHandler#q 'q.op' => TRUE, // http://wiki.apache.org/solr/SearchHandler#q.op diff --git a/apachesolr.module b/apachesolr.module index 440d4a0..5ccff0f 100644 --- a/apachesolr.module +++ b/apachesolr.module @@ -1546,7 +1546,7 @@ function apachesolr_static_response_cache($searcher, $response = NULL) { * * @throws Exception */ -function apachesolr_drupal_query($name, array $params = array(), $solrsort = '', $base_path = '', DrupalApacheSolrServiceInterface $solr = NULL) { +function apachesolr_drupal_query($name, array $params = array(), $solrsort = '', $base_path = '', DrupalApacheSolrServiceInterface $solr = NULL, $search_page = array()) { if (!interface_exists('DrupalSolrQueryInterface')) { require_once(dirname(__FILE__) . '/apachesolr.interface.inc'); } @@ -1561,7 +1561,8 @@ function apachesolr_drupal_query($name, array $params = array(), $solrsort = '', if (empty($solr)) { $solr = apachesolr_get_solr(); } - return new $class($name, $solr, $params, $solrsort, $base_path); + $page_id = array_key_exists('page_id', $search_page) ? $search_page['page_id'] : apachesolr_search_default_search_page(); + return new $class($name, $solr, $params, $solrsort, $base_path, $page_id); } /** diff --git a/apachesolr_search.module b/apachesolr_search.module index f75888a..5cc522c 100644 --- a/apachesolr_search.module +++ b/apachesolr_search.module @@ -876,7 +876,7 @@ function apachesolr_search_search_results($keys = NULL, $conditions = NULL, $sea if (!$keys && !isset($conditions['f']) && ($empty_search_behavior == 'browse' || $empty_search_behavior == 'blocks')) { // Pass empty search behavior as string on to apachesolr_search_search_page() // Hardcoded apachesolr name since we rely on this for the facets - apachesolr_search_run_empty('apachesolr', $params, $search_page['search_path'], $solr); + apachesolr_search_run_empty('apachesolr', $params, $search_page['search_path'], $solr, $search_page); $results['apachesolr_search_browse'] = $empty_search_behavior; if ($empty_search_behavior == 'browse') { @@ -888,7 +888,7 @@ function apachesolr_search_search_results($keys = NULL, $conditions = NULL, $sea elseif (($keys || isset($conditions['f'])) || ($empty_search_behavior == 'results')) { $params['q'] = $keys; // Hardcoded apachesolr name since we rely on this for the facets - $results = apachesolr_search_run('apachesolr', $params, $solrsort, $search_page['search_path'], pager_find_page(), $solr); + $results = apachesolr_search_run('apachesolr', $params, $solrsort, $search_page['search_path'], pager_find_page(), $solr, $search_page); } } catch (Exception $e) { @@ -1011,8 +1011,8 @@ function theme_apachesolr_search_browse_blocks($vars) { /** * Execute a search with zero results rows so as to populate facets. */ -function apachesolr_search_run_empty($name, array $params = array(), $base_path = '', $solr) { - $query = apachesolr_drupal_query($name, $params, '', $base_path, $solr); +function apachesolr_search_run_empty($name, array $params = array(), $base_path = '', DrupalApacheSolrServiceInterface $solr = NULL, $search_page = array()) { + $query = apachesolr_drupal_query($name, $params, '', $base_path, $solr, $search_page); $query->addParam('rows', '0'); $solr_id = $query->solr('getId'); list($final_query, $response) = apachesolr_do_query($query); @@ -1038,11 +1038,11 @@ function apachesolr_search_run_empty($name, array $params = array(), $base_path * * @throws Exception */ -function apachesolr_search_run($name, array $params = array(), $solrsort = '', $base_path = '', $page = 0, DrupalApacheSolrServiceInterface $solr = NULL) { +function apachesolr_search_run($name, array $params = array(), $solrsort = '', $base_path = '', $page = 0, DrupalApacheSolrServiceInterface $solr = NULL, $search_page = array()) { // Merge the default params into the params sent in. $params += apachesolr_search_basic_params(); // This is the object that knows about the query coming from the user. - $query = apachesolr_drupal_query($name, $params, $solrsort, $base_path, $solr); + $query = apachesolr_drupal_query($name, $params, $solrsort, $base_path, $solr, $search_page); if ($query->getParam('q')) { apachesolr_search_add_spellcheck_params($query);