-
Notifications
You must be signed in to change notification settings - Fork 3
/
IslandoraCOSolrResults.inc
155 lines (134 loc) · 4.99 KB
/
IslandoraCOSolrResults.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*
* contains methods to search solr and display results. depends on Apache_Solr_Php client.
*/
/**
* Extention of IslandoraSolrResults
* This overrides the printResults function to provide customized display.
*/
module_load_include('inc', 'islandora_solr_search', 'IslandoraSolrResults');
class IslandoraCOSolrResults 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 IslandoraSolrResults() {
module_load_include('php', 'islandora_solr_search', 'Solr/Service');
}
/**
*
* @param $results
* A solr resultset object.
*
* @return
* html output for the resultset. Note: we currently create this
* output manually, should refactor to use drupal forms api.
*/
function printResults($results) {
global $base_url;
if (empty($results)) {
return "no results";
}
$moduleRoot = drupal_get_path('module', 'islandora_co_solr_config');
drupal_add_css($moduleRoot . '/css/adr.css');
drupal_add_css($moduleRoot . '/css/jquery.lightbox-0.5.css');
drupal_add_js($moduleRoot . '/js/jquery.lightbox-0.5.modified.js');
drupal_add_js($moduleRoot . '/js/uofm.js');
drupal_add_js("$(document).ready(function () { $('.results a.zoomIcon').lightBox( { txtImage: 'Result', imageLoading: '$base_url/$moduleRoot/images/lightbox-icon-loading.gif', imageBtnClose: '$base_url/$moduleRoot/images/lightbox-btn-close.gif', imageBtnPrev: '$base_url/$moduleRoot/images/lightbox-btn-prev.gif', imageBtnNext: '$base_url/$moduleRoot/images/lightbox-btn-next.gif' }); });", 'inline');
$output = '';
$output.='<div class="results"/><table border="0" cellpadding="10" cellspacing="0" width="100%">';
$arg = join('/', arg());
$rawResponse = $results->getRawResponse();
$responseArray = json_decode($rawResponse, true);
$highlightResults = $responseArray['highlighting'];
$keys = array('');
$snippetArray = islandora_build_substitution_list(variable_get("islandora_solr_snippet_field", ""));
if (is_array($snippetArray)) {
$keys = array_keys($snippetArray);
}
$highlight_field = $keys[0];
$highlight_label = $snippetArray[$highlight_field];
foreach ($responseArray['response']['docs'] as $doc) {
$output .= $this->build_list($doc, $highlightResults, $highlight_field);
}
$output.='</table></div>';
return $output;
}
function build_list($doc, $highlightResults, $highlight_field, $link_to_object = TRUE) {
$pid = $doc['PID'];
$highlight_text = "";
if (is_array($highlightResults[$pid][$highlight_field])) {
$highlight_text = implode(' ', $highlightResults[$pid][$highlight_field]);
}
$title = $doc['Title'];
if (is_array($doc['Title'])) {
$title = (string) $title[0];
}
$output .= '<tr><td><div class="thumbnail">';
$img = "<img src='$base_url/fedora/repository/$pid/TN'/>";
$output .= l($img, "fedora/repository/$pid", array('attributes' => array('title' => $title), 'html' => 'true')) . '</div></td>';
$output .= '<td><div class="metadata">';
if($link_to_object == TRUE) {
$output .= '<a href="' . $base_url . '/fedora/repository/' . $pid . '">' . $title . '</a>';
}
$output .= '<ul>';
if (!empty($highlight_text)) {
$output .= '<li class="fulltext">';
if ($highlight_label) {
$output.="<b>$highlight_label</b> ";
}
$output .= $highlight_text;
$output .= '...';
$output .= '</li>';
}
if (!empty($doc['Abstract'])) {
$output.='<li class="gray">';
if (is_array($doc['Abstract'])) {
foreach ($doc['Abstract'] as $abstract) {
$output .= "$abstract";
}
}
else {
$output .=$doc['Abstract'];
}
$output .= '</li>';
}
if (!empty($doc['Creators'])) {
$output.='<li class="gray"><b>Created by:</b> ';
if (is_array($doc['Creators'])) {
foreach ($doc['Creators'] as $creators) {
$output .= "$creators; ";
}
}
else {
$output .=$doc['Creators'];
}
$output .= '</li>';
}
if (!empty($doc['Date_Created'])) {
$output.='<li class="gray"><b>Date Created:</b> ';
if (is_array($doc['Date_Created'])) {
foreach ($doc['Date_Created'] as $dateCreated) {
$output .= "$dateCreated";
}
}
else {
$output .= $doc['Date_Created'];
}
$output .= '</li>';
}
if (!empty($doc['Date_Issued'])) {
$output.='<li class="gray"><b>Publication Date:</b> ';
if (is_array($doc['Date_Issued'])) {
foreach ($doc['Date_Issued'] as $dateIssued) {
$output .= "$dateIssued";
}
}
else {
$output .= $doc['Date_Issued'];
}
$output .= '</li>';
}
$output.='</ul></div></td></tr>';
return $output;
}
}