/
Custom_Seach_Results_Solr_Base_Query.php
75 lines (66 loc) · 1.85 KB
/
Custom_Seach_Results_Solr_Base_Query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* @file
*/
module_load_include('php', 'apachesolr', 'Solr_Base_Query');
/**
* Custom class to extend the standard SolrBaseQuery class in order to fix a
* problem with the facet URLs pointing to wrong URL.
*/
class CustomSearchResultsSolrBaseQuery extends SolrBaseQuery {
/**
* Parameter to determine when to make the right redirect.
*/
protected $is_q_path = FALSE;
/**
* Constructor
*
* @param $env_id
* The environment where you are calling the query from. Typically the default environment.
*
* @param $solr
* An instantiated DrupalApacheSolrService Object.
* Can be instantiated from apachesolr_get_solr().
*
* @param $params
* Array of params to initialize the object (typically 'q' and 'fq').
*
* @param $sortstring
* Visible string telling solr how to sort - added to GET query params.
*
* @param $base_path
* The search base path (without the keywords) for this query, without trailing slash.
*/
public function __construct($name, $solr, array $params = array(), $sortstring = '', $base_path = '') {
parent::__construct($name, $solr, $params, $sortstring, $base_path);
}
/**
* Get the parameter that determins if to make the right redirect.
*/
public function getQPath() {
return $this->is_q_path;
}
/**
* Set the parameter that determins when to make the right redirect
*
* @param boolean $flag
*/
public function setQPath($flag) {
$this->is_q_path = $flag;
}
/**
* Get the right path to be redirected to.
* @see SolrBaseQuery::getPath()
*/
public function getPath($new_keywords = NULL) {
if ($this->is_q_path) {
return $_GET['q'];
}
else {
if (isset($new_keywords)) {
return $this->base_path . '/' . $new_keywords;
}
return $this->base_path . '/' . $this->getParam('q');
}
}
}