-
Notifications
You must be signed in to change notification settings - Fork 3
/
IslandoraCORSSResults.inc
139 lines (109 loc) · 4.48 KB
/
IslandoraCORSSResults.inc
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* @file
* contains methods to search solr and display results. depends on Apache_Solr_Php client.
*/
module_load_include('inc', 'islandora_solr_search', 'IslandoraSolrResults');
/**
* Extention of IslandoraSolrResults for templating purposes.
* This overrides the displayResults function to provide an alternate display type.
*/
class IslandoraCORSSResults extends IslandoraSolrResults {
static $facetSeparator = '~'; //used to separate facets in url
static $slashReplacement = '~slsh~'; // a pattern used to replace / in url's the slash breaks drupal clean url's
public static $SEARCH_CLASS_ADVANCED_SEARCH_NUMBER_FIELDS = 5;
function IslandoraCORSSResults() {
parent::__construct();
//module_load_include('php', 'islandora_solr_search', 'Solr/Service');
}
function printRSS($solrQueryProcessor, $title = "Search Results") {
global $base_url;
module_load_include('inc', 'islandora_co_solr_config', 'IslandoraCOSolrResults');
$co_results = new IslandoraCOSolrResults();
$lowerLimit = 0;
$docs = array();
// set limit to rss items.
$limit = variable_get('islandora_solr_search_num_of_results', 20);
if (isset($_GET['limit'])) {
$limit = $_GET['limit'];
}
if($limit == -1) {
$limit = 30000;
}
$solrQueryProcessor->solrParams['hl'] = '';
$solrQueryProcessor->solrParams['hl.fl'] = '';
$solrQueryProcessor->solrStart = $lowerLimit;
$solrQueryProcessor->solrLimit = $limit;
$solrQueryProcessor->executeQuery();
if($solrQueryProcessor->solrResult) {
$rawResponse = $solrQueryProcessor->solrResult->getRawResponse();
$responseData = json_decode($rawResponse, true);
$docs = $responseData['response']['docs'];
}
// this is where we switch to rss view
drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
// set variables
$result = array();
$item = array();
$feed = '';
if (isset($_GET['feed'])) {
$feed = $_GET['feed'];
}
// render the single rss <item> elements
foreach ($docs as $key => $doc) {
if (empty($doc['Title'])) {
continue;
}
// some values are located in a single array. Revert this:
$rss_source = variable_get('site_name', "Default site name");
$rss_source_url = $base_url;
foreach ($doc as $key => $value) {
if (is_array($value) AND count($value == 1)) {
$doc[$key] = $value[0];
}
}
$result = array();
$result['title'] = $doc['Title'];
//$result['link'] = $base_url . '/fedora/repository/' . htmlspecialchars($doc['PID'], ENT_QUOTES, 'utf-8');
$result['link'] = $base_url . '/fedora/repository/' . $doc['PID'];
$result['description'] = '<table>' . $co_results->build_list($doc, null, null, FALSE) .'</table>';
$result['items'] = array(
array('key' => 'guid', 'value' => $doc['PID'], 'attributes' => array('isPermaLink' => 'false',)),
array('key' => 'pubDate', 'value' => $doc['fgs.createdDate']),
array('key' => 'category', 'value' => $doc['Subjects']),
//array('key' => 'enclosure', 'value' => '', 'attributes' => array('url' => '', 'length' => '', 'type' => '')),
array('key' => 'comments', 'value' => ''),
array('key' => 'source', 'value' => $rss_source, 'attributes' => array('url' => $rss_source_url)),
);
$item[] = $result;
}
$items = '';
foreach ($item as $feed) {
$items .= format_rss_item($feed['title'], $feed['link'], $feed['description'], $feed['items']);
}
// query search terms:
$query = $solrQueryProcessor->solrQuery;
// get the variables for the <channel> element
$channel = prepare_rss_channel($query, $feed);
// give the results clean variable names.
$title = $channel['title'];
$url = $channel['url'];
$description = $channel['description'];
$langcode = $channel['langcode'];
$args = $channel['args'];
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output .= "<rss version=\"2.0\">\n";
$output .= format_rss_channel($title, $url, $description, $items, $langcode, $args);
$output .= "</rss>\n";
print $output;
}
}
function prepare_rss_channel($query, $feed) {
global $base_url;
$result['title'] = t('@site_name aggregator', array('@site_name' => variable_get('site_name', 'Drupal')));
$result['url'] = $base_url;
$result['description'] = t('Aggregated search results of:') . ' ' . $query;
$result['langcode'] = NULL;
$result['args'] = array();
return $result;
}