-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresults.php
More file actions
193 lines (164 loc) · 5.87 KB
/
results.php
File metadata and controls
193 lines (164 loc) · 5.87 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
include('app/app.php');
include('rest/EBSCOAPI.php');
$api = new EBSCOAPI();
// Build the arguments for the Search API method
$searchTerm = str_replace('"','',$_REQUEST['query']);
$fieldCode = $_REQUEST['fieldcode']? $_REQUEST['fieldcode'] :'';
$start = isset($_REQUEST['pagenumber']) ? $_REQUEST['pagenumber'] : 1;
$limit = isset($_REQUEST['resultsperpage'])?$_REQUEST['resultsperpage']:20;
$sortBy = isset($_REQUEST['sort'])?$_REQUEST['sort']:'relevance';
$amount = isset($_REQUEST['view'])?$_REQUEST['view']:'detailed';
$mode = 'all';
$expander = isset($_REQUEST['expander'])? $_REQUEST['expander']:'';
$debug = isset($_REQUEST['debug'])? $_REQUEST['debug']:'';
$Info = $api->getInfo();
$autoSuggest = $api->getAutoSuggestState($Info);
$autoCorrect = $api->getAutoCorrectState($Info);
$imageQuickView = $api->getImageQuickViewState($Info);
$relatedContent = $api->getRelatedContentOptions($Info);
$publicationId = isset($_REQUEST['publicationid'])?$_REQUEST['publicationid']:'';
//when clicking on the "original term" for an autocorrected query, we must be able to override the info method
if (isset($_REQUEST['autocorrect']) && $_REQUEST['autocorrect'] == 'n'){
$autoCorrect = 'n';
}
// If user come back from the detailed record
// The same search will not call API again
if(isset($_REQUEST['back'] )&&isset($_SESSION['results'])){
$results = $_SESSION['results'];
}else if(isset($_REQUEST['option'])){
// All page options will be handled here
// New Search or refined search will call the API
$results = $_SESSION['results'];
$queryStringUrl = $results['queryString'];
$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
$actions = array();
if(!empty($action)){
if(strstr($action, 'setsort(')){
$sortBy = str_replace(array('setsort(',')'),array('',''), $action);
$start = 1;
}
if(strstr($action, 'setResultsperpage(')){
$limit = str_replace(array('setResultsperpage(',')'),array('',''), $action);
}
if(strstr($action, 'GoToPage(')){
$start = str_replace(array('GoToPage(',')'),array('',''), $action);
}
$actions['action'] = $action;
}
$view = isset($_REQUEST['view'])? array('view'=>$_REQUEST['view']):array();
$params = array_merge($actions,$view);
$url = $queryStringUrl.'&'.http_build_query($params);
$results = $api->apiSearch($url);
// Will save the result into the session with the new SessionToken as index
$_SESSION['results'] = $results;
}else if(isset($_REQUEST['refine'])||isset($_GET['login'])){
// New Search or refined search will call the API
if(isset($_REQUEST['action'])){
$actions = $_REQUEST['action'];
}else{
$actions = '';
}
$refineActions = array();
if(is_array($actions)){
for($i=0; $i<count($actions);$i++){
$refineActions['action-'.($i+1)]= $actions[$i+1];
}
}else{
$refineActions['action'] = $actions;
}
$results = $_SESSION['results'];
$queryStringUrl = $results['queryString'];
$params = http_build_query($refineActions);
$url = $queryStringUrl.'&'.$params;
$results = $api->apiSearch($url);
$_SESSION['results'] = $results;
if(isset($_REQUEST['refine']))$start = 1;
}else{
$query = array();
// Basic search
if(!empty($searchTerm)) {
$term = urldecode($searchTerm);
$term = str_replace('"', '', $term); // Temporary
$term = str_replace(',',"\,",$term);
$term = str_replace(':', '\:', $term);
$term = str_replace('(', '\(', $term);
$term = str_replace(')', '\)', $term);
if($fieldCode!='keyword'){
$query_str = implode(":", array($fieldCode, $term));
}else{
$query_str = $term;
}
$query["query"] = $query_str;
// No search term, return an empty array
} else {
$results = array();
}
// Add the HTTP query params
$params = array(
// Specifies the sort. Valid options are:
// relevance, date, date2
// date = Date descending
// date2 = Date descending
'sort' => $sortBy,
// Specifies the search mode. Valid options are:
// bool, any, all, smart
'searchmode' => $mode,
// Specifies the amount of data to return with the response. Valid options are:
// Title: title only
// Brief: Title + Source, Subjects
// Detailed: Brief + full abstract
'view' => $amount,
// Specifies whether or not to include facets
'includefacets' => 'y',
'resultsperpage' => $limit,
'pagenumber' => $start,
// Specifies whether or not to include highlighting in the search results
'highlight' => 'y',
'expander' => $expander,
//related content
// rs = Research Starter; emp = Exact Match Placard
'relatedcontent' => $relatedContent,
//autosuggest
'autosuggest' => $autoSuggest,
//autocorrect
'autocorrect' => $autoCorrect,
//Image Quick View
'includeimagequickview' => $imageQuickView,
//publication ID
'publicationid' => $publicationId
);
$params = array_merge($params, $query);
$params = http_build_query($params);
$results = $api->apiSearch($params);
//Cach the results for each session
$_SESSION['results'] = $results;
}
// Error
if (isset($results['error'])) {
$error = $results['error'];
$results = array();
} else {
$error = null;
}
//save debug into session
if($debug == 'y'||$debug == 'n'){
$_SESSION['debug'] = $debug;
}
// Variables used in view
$variables = array(
'searchTerm' => $searchTerm,
'fieldCode' => $fieldCode,
'results' => $results,
'error' => $error,
'start' => $start,
'limit' => $limit,
'refineSearchUrl'=> '',
'amount' => $amount,
'sortBy' => $sortBy,
'id' => 'results',
'Info' => $Info,
'debug' => isset($_SESSION['debug'])? $_SESSION['debug']:''
);
render('results.html', 'layout.html', $variables);
?>