-
Notifications
You must be signed in to change notification settings - Fork 64
/
IslandoraSolrResults.inc
559 lines (526 loc) · 25.8 KB
/
IslandoraSolrResults.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
<?php
/*
* contains methods to search solr and display results. depends on Apache_Solr_Php client.
*/
class 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');
}
function parseQuery($solr, $query,$dismax=false) {
$query = str_replace(IslandoraSolrResults::$slashReplacement,'/',$query); //can't have a slash in the url breaks drupal clean urls
return $query;
}
//default implementation for solr search. You can configure others in the block config settings
function searchAndDisplay($query,$startPage=1,$fq=null,$dismax=null) {
$limit = variable_get('islandora_solr_search_num_of_results',20);
global $islandora_solrQuery, $islandora_solr_page_number, $base_url;//used by facect block as well
$islandora_solr_page_number = $startPage;
$islandora_solrQuery = str_replace('/',IslandoraSolrResults::$slashReplacement,$query);//replace the slash so we can use this in a url without breaking drupal clean urls
if(empty($islandora_solrQuery)) {
$islandora_solrQuery='%20';//so we can allow empty queries to dismax
}
// module_load_include('php', 'fedora_repository', 'Solr/Service');
$host = variable_get('islandora_solr_search_block_host','localhost');
$port = variable_get('islandora_solr_search_block_port','8080');
$appName = variable_get('islandora_solr_search_block_app_name','solr');
$solr = new Apache_Solr_Service($host, $port, '/'.$appName.'/');
$query = $this->parseQuery($solr,$query,$dismax,$solr);//fix the query as some characters will break the search : and / slash are examples
$facetlimit = variable_get('islandora_solr_search_block_facet_limit','12');
$facetMinCount = variable_get('islandora_solr_search_block_facet_min_count','2');
$requestHandler = variable_get("islandora_solr_search_block_request_handler",t("standard"));
$additionalParams = array(
'facet' => 'true',
'facet.mincount' => $facetMinCount,
'facet.limit' => $facetlimit,
'qt' => $requestHandler,
'facet.field' => explode(',',variable_get("islandora_solr_search_block_facets",'dc.subject,dc.type')),//comma separated list configured in the block config
);
global $islandora_fq;
if($fq != NULL && $fq != '-') {
$fq = str_replace(IslandoraSolrResults::$slashReplacement,'/',$fq);//put the slash back
if(strpos($fq,'-')===0) {//remove the requested facet from the list
$fq = substr($fq,strpos($fq,IslandoraSolrResults::$facetSeparator)+1);
}
$fqs = $this->solr_escape($this->csv_explode(IslandoraSolrResults::$facetSeparator,$fq,'"',true));//to filter by more then one facet we will separate them by~ for now
$additionalParams['fq'] = $fqs;
$islandora_fq = str_replace('/',IslandoraSolrResults::$slashReplacement,$fq);//remove the slash here as we will be using this in url's
}
if(empty($islandora_fq)) {
$islandora_fq = '-';
}
global $islandora_defType;
if($dismax != NULL) {
$islandora_defType = $dismax;
$additionalParams['defType'] =$dismax;
}
$recordStart = $startPage -1;
$recordStart = max(0,$recordStart);//don't want a negative number
$recordStart = $recordStart * $limit;
try {
$results = $solr->search($query, $recordStart, $limit,$additionalParams);
}catch (Exception $e) {
drupal_set_message(t('error searching ').$e->getMessage());
}
if(empty($results)){
drupal_set_message(t('Error searching solr index. Is the solr search block configured properly?'),'error');
return ' ';
}
$total = (int) $results->response->numFound;
$start = min(1, $total);
$end = min(($limit + $recordStart), $total);
$output .='<div>Results '.($recordStart + 1).' - '. $end .' of '. $total.'</div>';
$output .='<div class="item-list"><ul class = "pager">';//opening div for paging links
if($recordStart > 0) {
$output .='<li class="pager-previous"><a href="'.$base_url.'/islandora/solr/search/'.htmlspecialchars(drupal_urlencode($islandora_solrQuery),ENT_QUOTES,'utf-8',false).'/'.max(0,($startPage-1)).'/'.htmlspecialchars($islandora_fq,ENT_QUOTES,'utf-8',false).'/'.$dismax.'">‹ previous</a></li> ';
}
if($recordStart < ($total-$limit)) {
$output .='<li class = "pager-next"><a href="'.$base_url.'/islandora/solr/search/'.htmlspecialchars(drupal_urlencode($islandora_solrQuery),ENT_QUOTES,'utf-8',false).'/'.($startPage+1).'/'.htmlspecialchars($islandora_fq,ENT_QUOTES,'utf-8',false).'/'.$dismax.'">next ›</a></li>';
}
$output .= '</div></ul>';//added closing div for drupal paging here
//call a function defined in the blocks config
$solrFile = trim(variable_get('islandora_solr_search_block_handler_file','IslandoraSolrResults.inc'));
if(strpos($solrFile,'../')){//don't let us bust out of islandora_solr_search modules directory when looking for a handler
drupal_set_message(t('You have illegal characters in your solr handler function in the Islandora solr block config.'), 'error');
return ' ';
}
$solrClass = trim(variable_get('islandora_solr_search_block_handler_class','SolrResults'));
$solrFunction = trim(variable_get('islandora_solr_search_block_handler_function','SearchAndDisplay'));
require_once(drupal_get_path('module', 'islandora_solr_search') . '/'. $solrFile);
//try {
if(class_exists($solrClass)){
$implementation = new $solrClass();
} else {
drupal_set_message(t('Error loading solr results class. Class could not be loaded. Check the Islandora Solr search blocks configuration.'),'error');
return ' ';
}
//} catch (Exception $e) {
// watchdog(t("Fedora_Repository"), t("Error Getting Solr Search Results Class!") . $e->getMessage(), NULL, WATCHDOG_ERROR);
// return 'Error getting Solr Search Results class. Check watchdog for more info.';
// }
if(method_exists($implementation,$solrFunction)){
$output.= $implementation->$solrFunction($results);
if( variable_get('islandora_solr_search_debug_mode', 0) ) { // debug dump
drupal_set_message('Params: <br/><pre>' . print_r($additionalParams,true) . '</pre>' ,'status');
}
} else {
drupal_set_message(t('Error loading solr results class. Could not find the specified method. Check the Islandora Solr search blocks configuration.'),'error');
}
global $islandora_facets;//make facets available to the islandora facet block
$islandora_facets = $results->facet_counts->facet_fields;
return $output;
}
//default implementation of display results can be changed in the blocks config
function displayResults($results){
$output.= '<ol start="'.($recordStart + 1).'">';
global $base_url;
if(empty($results)) {
return "no results";
}
foreach($results->response->docs as $doc) {
$output .= '<li><table>';
foreach($doc as $field => $value) {
$output .= '<tr><th>'.$field.'</th>';
if(is_array($value)) {
$value = implode(", ",$value);
}
if($field=='PID') {
$output.='<td><a href="'.$base_url.'/fedora/repository/'.htmlspecialchars($value,ENT_QUOTES,'utf-8').'">'.$value.'</td>';
}else {
$output .= '<td>'.$value.'</td>';
}
}
$output .='</table></li>';
}
$output .= '</ol>';
if( variable_get('islandora_solr_search_debug_mode', 0) ) { // debug dump
$results_r .= "<pre>Results: ".print_r($results,true)."</pre>";
$fieldset_r = array(
'#title' => t("Raw Results"),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $results_r,
);
$output .= theme('fieldset', $fieldset_r);
}
return $output;
}
//called from the islandora facet block
function displayFacets() {
global $islandora_facets, $islandora_defType, $islandora_solrQuery, $base_url, $islandora_fq;
$output = '<div class = "item-list">';
if( strlen( trim( $islandora_solrQuery ) ) ) {
$output .= '<div class="islandora_solr_search_search_wrap">';
$output .= '<div class="islandora_solr_search_facet_title">'.t('Base Query').':</div>';
$output .= '<div class="islandora_solr_search_facet_value_enabled">'.$islandora_solrQuery;
$output .= ' <a href="'.$base_url.'/islandora/solr/search/'.htmlspecialchars(drupal_urlencode(" "),ENT_QUOTES,'utf-8',false).'/'.($startPage+1).'/'.htmlspecialchars($islandora_fq,ENT_QUOTES,'utf-8',false).'/dismax"><img class="islandora_solr_add_remove_link" src="/'.drupal_get_path('module', 'islandora_solr_search').'/images/delete.png" alt="Remove search term"></a>';
$output .= '</div>'; // 'islandora_solr_search_facet_value_enabled'
$output .= '</div>'; // 'islandora_solr_search_search_wrap'
}
if(empty($islandora_facets)) {
return ''; //no facets to show
}
foreach($islandora_facets as $key => $field) {
$test = get_object_vars($field);//get the number of fields if there aren't any don't show the key
if (count($test)>0) {
$facet_count = 0;
unset( $normal_facet_output );
$filter_query;
foreach($field as $name=>$number) {
if($islandora_fq && $islandora_fq != '-') {//there are existing facets in the query
$disable_link = strstr($islandora_fq,$key.':"'.str_replace('/',IslandoraSolrResults::$slashReplacement,$name).'"');//we don't want a link for this facet as we already used it
if($disable_link) { //don't show link to this facet but include a link to remove it
$edited_list = str_replace($key.':"'.str_replace('/',IslandoraSolrResults::$slashReplacement,$name).'"', '', $islandora_fq); //remove the filter query from the list
$edited_list = str_replace(IslandoraSolrResults::$facetSeparator.IslandoraSolrResults::$facetSeparator, IslandoraSolrResults::$facetSeparator, $edited_list); //cut out duplicate field separators
$edited_list = trim($edited_list,IslandoraSolrResults::$facetSeparator); //cut off trailing field separators
$filter_query = htmlspecialchars(drupal_urlencode($edited_list),ENT_QUOTES,'utf-8',false);
} else {
$filter_query = $key . ':' . htmlspecialchars('"'.drupal_urlencode($name).'"',ENT_QUOTES,'utf-8',false). IslandoraSolrResults::$facetSeparator . htmlspecialchars(drupal_urlencode($islandora_fq),ENT_QUOTES,'utf-8',false);
}
} else { //no existing facets chosen
$filter_query = $key . ':' . htmlspecialchars('"'.drupal_urlencode($name).'"',ENT_QUOTES,'utf-8');
}
$filter_query = str_replace('/',IslandoraSolrResults::$slashReplacement,$filter_query);//replace the slash so url does not break
if( empty( $filter_query ) ) {
$filter_query = '-';
}
if($disable_link) {//create a link to remove this facet as it has already been chosen
$filter_output .= '<li><div>'.$key.' = '.$name ; //no href here
$filter_output .= ' <a href="'.$base_url.'/islandora/solr/search/'.htmlspecialchars(drupal_urlencode($islandora_solrQuery),ENT_QUOTES,'utf-8',false).'/1/'.$filter_query.'/'.$islandora_defType.'"/><img class="islandora_solr_add_remove_link" src="/'.drupal_get_path('module', 'islandora_solr_search').'/images/delete.png" alt="Remove this filter"></a> ';
$filter_output .= "</div></li>";
} else {//normal link
$normal_facet_output .= '<li><div><a href="'.$base_url.'/islandora/solr/search/'.htmlspecialchars(drupal_urlencode($islandora_solrQuery),ENT_QUOTES,'utf-8',false).'/1/'.$filter_query.'/'.$islandora_defType.'"/>'.$name.'</a> ('.$number.')</div></li>';
$facet_count++;
}
}
if( $facet_count >=2 ) {
$facet_output .='<div class="islandora_solr_search_facet_wrap">';
$facet_output .='<div class="islandora_solr_search_facet_name">'. htmlspecialchars($key, ENT_QUOTES, 'utf-8').'</div>';
$facet_output .='<ul>';
$facet_output .= $normal_facet_output;
$facet_output .='</ul>';
$facet_output .='</div>';
}
}
}
if(!empty($filter_output)) {
$output .= '<div class="islandora_solr_search_search_wrap">';
$output .= '<div class="islandora_solr_search_facet_title">'.t('Enabled Filters').':</div>';
$output .= '<div class="islandora_solr_search_enabled_filters"><ul class="filter_list">'.$filter_output.'</ul></div>';
$output .= '</div>'; // 'islandora_solr_search_search_wrap'
}
$output .='<div class="islandora_solr_search_facets">';
$output .= $facet_output;
$output .= '</div>';
$output .= '</div>';
return $output;
}
//a better explode method allows quotes in the returned strings. taken from the php.net site
function csv_explode($delim=',', $str, $enclose='"', $preserve=false) {
$resArr = array();
$n = 0;
$expEncArr = explode($enclose, $str);
foreach($expEncArr as $EncItem) {
if($n++%2) {
array_push($resArr, array_pop($resArr) . ($preserve?$enclose:'') . $EncItem.($preserve?$enclose:''));
}else {
$expDelArr = explode($delim, $EncItem);
array_push($resArr, array_pop($resArr) . array_shift($expDelArr));
$resArr = array_merge($resArr, $expDelArr);
}
}
return $resArr;
}
//copied from apache solr service and added space as a value to escape. We are using this to escape the field being searched not the text being searched for so we need both.
public function escape($value)
{
//list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:| |\\\)/';
$replace = '\\\$1';
return preg_replace($pattern, $replace, $value);
}
//escape characters in field names of facets
function solr_escape($facets){
$returnFacets = array();
foreach ($facets as $facet){
$tmp = substr($facet,0,strpos($facet,':"'));
$tmp = $this->escape(trim($tmp));
$returnFacets[] = $tmp . substr($facet,strpos($facet,':"'),strlen($facet));
}
return $returnFacets;
}
function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) {
$types = $this->get_search_terms_array(NULL,'solrSearchTerms.xml');
$queryArray=NULL;
if (isset($query)) {
$queryArray = explode('AND', $query);
}
$andOrArray = array(
'AND' => 'and',
//'OR' => 'or' //removed or for now as it would be a pain to parse
);
$form = array();
if (!isset($repeat)) {
$repeat = variable_get('islandora_solr_search_block_repeat', t('3'));
}
$var0 = explode(':', $queryArray[0]);
$var1 = explode(':', $queryArray[1]);
$form['search_type']['type1'] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => trim($var0[0])
);
$form['fedora_terms1'] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#required' => TRUE,
'#default_value' => (count($var0) >= 2 ? trim($var0[1]) : ''),
);
$form['andor1'] = array(
'#title' => t(''),
'#type' => 'select',
'#default_value' => 'AND',
'#options' => $andOrArray
);
$form['search_type']['type2'] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => (count($var1) >= 2 ? trim($var1[0]) : ''),
);
$form['fedora_terms2'] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#default_value' => (count($var1) >= 2 ? $var1[1] : ''),
);
if ($repeat>2 && $repeat < 9) { //don't want less then 2 or more then 9
for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1;
$field_and_term = explode(':', $queryArray[$t]);
$form["andor$t"] = array(
'#title' => t(''),
'#type' => 'select',
'#default_value' => 'AND',
'#options' => $andOrArray
);
$form['search_type']["type$i"] = array(
'#title' => t(''),
'#type' => 'select',
'#options' => $types,
'#default_value' => trim($field_and_term[0])
);
$form["fedora_terms$i"] = array(
'#size' => '24',
'#type' => 'textfield',
'#title' => t(''),
'#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''),
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('search')
);
return $form;
}
function build_simple_solr_form(){
//$form = array();
$form["islandora_simple_search_query"] = array(
'#size' => '24%',
'#type' => 'textfield',
'#title' => t(''),
// '#default_value' => (count($field_and_term) >= 2 ? trim($field_and_term[1]) : ''),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('search')
);
return $form;
}
function theme_solr_search_form($form) {
if (!isset($repeat)) {
$repeat = variable_get('islandora_solr_search_block_repeat', t('3'));
}
$output = drupal_render($form['search_type']['type1']) ;
$output .= drupal_render($form['fedora_terms1']) ;
$output .= drupal_render($form['andor1']) . drupal_render($form['search_type']['type2']) ;
$output .= drupal_render($form['fedora_terms2']);
if ($repeat>2 && $repeat < 9) {
for ($i=3;$i<$repeat+1;$i++) {
$t = $i - 1;
$output .= drupal_render($form["andor$t"]) . drupal_render($form['search_type']["type$i"]) ;
$output .= drupal_render($form["fedora_terms$i"]) ;
}
}
$output .= drupal_render($form['submit']) ;
$output .= drupal_render($form);
return $output;
}
function mapsDisplay($results) {
$output.= '<ol start="'.($recordStart + 1).'">';
global $base_url;
if(empty($results)) {
return "no results";
}
foreach($results->response->docs as $doc) {
$output .= '<li><table>';
$rowspan = 0;
$pidValue = null;
$output .= '<tr>';
$output .= '<td ><img src="'.$base_url.'/fedora/repository/'.htmlspecialchars($doc->PID,ENT_QUOTES,'utf-8').'/TN"/></td>';
$output .= '<td><table>';
foreach($doc as $field => $value) {
$rowspan++;
$output .= '<tr><th>'.$field.'</th>';
if(is_array($value)) {
$value = implode(", ",$value);
}
if($field=='PID') {
$pidValue=$value;
$output.='<td><a href="'.$base_url.'/fedora/repository/'.htmlspecialchars($value,ENT_QUOTES,'utf-8').'">'.$value.'</td></tr>';
}else {
$output .= '<td>'.$value.'</td></tr>';
}
}
$output .='</table></td></tr></table></li>';
}
$output .= '</ol>';
return $output;
}
//this function will be removed. class has been refactored so we only need the display loop. leaving here until mnpl is updated.
function mnplSearchAndDisplay($query,$startPage=1,$fq=null,$dismax=null) {
$limit = variable_get('islandora_solr_search_num_of_results',20);
global $islandora_solrQuery, $islandora_solr_page_number, $base_url;//used by facect block as well
$islandora_solr_page_number = $startPage;
$islandora_solrQuery = str_replace('/',IslandoraSolrResults::$slashReplacement,$query);//replace the slash so we can use this in a url without breaking drupal clean urls
if(empty($islandora_solrQuery)){
$islandora_solrQuery='%20';//so we can allow empty queries to dismax
}
// module_load_include('php', 'fedora_repository', 'Solr/Service');
$host = variable_get('islandora_solr_search_block_host','localhost');
$port = variable_get('islandora_solr_search_block_port','8080');
$appName = variable_get('islandora_solr_search_block_app_name','solr');
$solr = new Apache_Solr_Service($host, $port, '/'.$appName.'/');
$query = $this->parseQuery($solr,$query,$dismax,$solr);//fix the query as some characters will break the search : and / slash are examples
$facetlimit = variable_get('islandora_solr_search_block_facet_limit','12');
$facetMinCount = variable_get('islandora_solr_search_block_facet_min_count','2');
$requestHandler = variable_get("islandora_solr_search_block_request_handler",t("standard"));
$additionalParams = array(
'facet' => 'true',
'facet.mincount' => $facetMinCount,
'facet.limit' => $facetlimit,
'qt' => $requestHandler,
'facet.field' => explode(',',variable_get("islandora_solr_search_block_facets",'dc.subject,dc.type')),//comma separated list configured in the block config
);
global $islandora_fq;
if($fq != NULL && $fq != '-') {
$fq = str_replace(IslandoraSolrResults::$slashReplacement,'/',$fq);//put the slash back
if(strpos($fq,'-')===0){//remove the requested facet from the list
$fq = substr($fq,strpos($fq,IslandoraSolrResults::$facetSeparator)+1);
}
$fqs = $this->csv_explode(IslandoraSolrResults::$facetSeparator,$fq,'"',true);//to filter by more then one facet we will separate them by~ for now
$additionalParams['fq'] = $fqs;
$islandora_fq = str_replace('/',IslandoraSolrResults::$slashReplacement,$fq);//remove the slash here as we will be using this in url's
}
if(empty($islandora_fq)) {
$islandora_fq = '-';
}
global $islandora_defType;
if($dismax != NULL) {
$islandora_defType = $dismax;
$additionalParams['defType'] =$dismax;
}
$recordStart = $startPage -1;
$recordStart = max(0,$recordStart);//don't want a negative number
$recordStart = $recordStart * $limit;
try {
$results = $solr->search($query, $recordStart, $limit,$additionalParams);
}catch (Exception $e) {
drupal_set_message(t('error searching ').$e->getMessage());
}
$total = (int) $results->response->numFound;
$start = min(1, $total);
$end = min(($limit + $recordStart), $total);
$output .='<div>Results '.($recordStart + 1).' - '. $end .' of '. $total.'</div>';
$output .='<div class="item-list"><ul class = "pager">';//opening div for paging links
if($recordStart > 0) {
$output .='<li class="pager-previous"><a href="'.$base_url.'/fedora/repository/solr_search/'.htmlspecialchars(drupal_urlencode($islandora_solrQuery),ENT_QUOTES,'utf-8',false).'/'.max(0,($startPage-1)).'/'.htmlspecialchars($islandora_fq,ENT_QUOTES,'utf-8',false).'/'.$dismax.'">‹ previous</a></li> ';
}
if($recordStart < ($total-$limit)) {
$output .='<li class = "pager-next"><a href="'.$base_url.'/fedora/repository/solr_search/'.htmlspecialchars(drupal_urlencode($islandora_solrQuery),ENT_QUOTES,'utf-8',false).'/'.($startPage+1).'/'.htmlspecialchars($islandora_fq,ENT_QUOTES,'utf-8',false).'/'.$dismax.'">next ›</a></li>';
}
$output .= '</div></ul>';//added closing div for drupal paging here
//most formatting of results happens in the loop below. maybe pull this out to a function
$output.= '<ol start="'.($recordStart + 1).'">';
global $base_url;
if(empty($results)) {
return "no results";
}
foreach($results->response->docs as $doc) {
$output .= '<li>';
$pidValue='';
$genusValue='';
$speciesValue='';
$keyValue;
foreach($doc as $field => $value) {
//var_dump($doc);
if(is_array($value)) {
$value = implode(" ",$value);
}
if($field=='PID') {
$pidValue=$value;
}else if ($field=='genus') {
$genusValue=$value;
}else if ($field=='specimen.species') {
$speciesValue=$value;
}else if ($field=='lab_id') {
$keyValue=$value;
}
}
$typeString='Specimen';
if($index=(strpos($pidValue,'-F-',TRUE))) {
$pidForImage = substr($pidValue,0,$index);
$pidForImage = str_replace('fraction','specimen',$pidForImage);
$typeString='Fraction';
}else if($index=(strpos($pidValue,'-C-',TRUE))) {
$pidForImage = strstr($pidValue,0,$index);
$pidForImage = str_replace('compound','specimen',$pidForImage);
$typeString='Compound';
}else {
$pidForImage = $pidValue;
}
$output.='<img src="'.$base_url.'/fedora/repository/'.htmlspecialchars($pidForImage,ENT_QUOTES,'utf-8').'/TN"/><a href="'.$base_url.'/fedora/repository/'.htmlspecialchars($pidValue,ENT_QUOTES,'utf-8').'"><strong>'.$typeString.'</strong>'.$keyValue.': '.$genusValue.' '.$speciesValue.'</a> ';
$output .='</li>';
}
$output .= '</ol>';
global $islandora_facets;//make facets available to the islandora facet block
$islandora_facets = $results->facet_counts->facet_fields;
return $output;
}
function get_search_terms_array($path = NULL,$file = NULL) {
if (!isset($path)) {
$path = drupal_get_path('module', 'islandora_solr_search');
}
$xmlDoc = new DomDocument();
if(!isset($file)) {
$file = 'searchTerms.xml';
}
$xmlDoc->load($path . '/'. $file);
$nodeList = $xmlDoc->getElementsByTagName('term');
$types = array();
for ($i = 0; $i < $nodeList->length; $i++) {
$field = $nodeList->item($i)->getElementsByTagName('field');
$value = $nodeList->item($i)->getElementsByTagName('value');
$fieldValue = $field->item(0)->nodeValue;
$valueValue = $value->item(0)->nodeValue;
$types["$fieldValue"] = "$valueValue";
}
return $types;
}
}
?>