forked from Islandora/islandora_solr_search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_solr_search.admin.inc
799 lines (712 loc) · 35.2 KB
/
islandora_solr_search.admin.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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
<?php
/**
* @file
* Admin functionality
*
* Contains all admin related functionality
*/
/**
* Function to return admin setting form
* @return array
*/
function islandora_solr_admin_settings(&$form_state) {
//checks for existence of PHP Solr client.
if (module_exists('apachesolr')) {
module_load_include('php', 'apachesolr', 'SolrPhpClient/Apache/Solr/Service');
}
else {
module_load_include('php', 'islandora_solr_search', 'SolrPhpClient/Apache/Solr/Service');
}
if (!class_exists('Apache_Solr_Service')) {
$message = t('This module requires the !url. Please install the client directory in the root directory of this module before continuing.', array('!url' => l(t('Apache Solr php client'), 'http://code.google.com/p/solr-php-client')));
drupal_set_message(check_plain($message));
return;
}
$handlers['standard'] = 'standard';
$handler = !empty($form_state['values']['islandora_solr_search_block_request_handler']) ? $form_state['values']['islandora_solr_search_block_request_handler'] : variable_get('islandora_solr_search_block_request_handler', 'standard');
$solr_url = !empty($form_state['values']['islandora_solr_search_block_url']) ? $form_state['values']['islandora_solr_search_block_url'] : variable_get('islandora_solr_search_block_url', 'localhost:8080/solr');
$solr_avail = solr_available($solr_url);
$dismax_allowed = FALSE;
if ($solr_avail) {
$handlers = get_handlers($solr_url);
$dismax_allowed = check_dismax($solr_url, $handler);
}
$confirmation_message = ($solr_avail ? '<img src="' . url('misc/watchdog-ok.png') . '"/>'
. t('Successfully connected to Solr server at !islandora_solr_search_block_url', array('!islandora_solr_search_block_url' => $solr_url)) : '<img src="'
. url('misc/watchdog-error.png') . '"/> '
. t('Unable to connect to Solr server at !islandora_solr_search_block_url</p>', array('!islandora_solr_search_block_url' => $solr_url)));
$form = array();
$form['solr_ahah_wrapper'] = array(
'#prefix' => '<div id="solr-url">',
'#suffix' => '</div>',
'#type' => 'fieldset',
);
$form['solr_ahah_wrapper']['islandora_solr_search_block_url'] = array(
'#type' => 'textfield',
'#title' => t('Solr url'),
'#size' => 40,
'#weight' => -1,
'#description' => t('The url of the Solr installation. Defaults to localhost:8080/solr.'),
'#default_value' => $solr_url,
'#ahah' => array(
'path' => 'islandora/solr/process',
'wrapper' => 'solr-url',
'effect' => 'fade',
'event' => 'blur',
),
);
$form['solr_ahah_wrapper']['refresh_page'] = array(
'#type' => 'submit',
'#value' => t('Test connection'),
'#attributes' => array('class' => 'refresh-button'),
'#submit' => array('solr_admin_refresh'),
);
$form['solr_ahah_wrapper']['infobox'] = array(
'#type' => 'item',
'#value' => $confirmation_message,
);
$form['solr_ahah_wrapper']['islandora_solr_search_block_request_handler'] = array(
'#type' => 'select',
'#title' => t('Request Handler'),
'#options' => $handlers,
'#description' => t('Request handlers as defined by !config', array('!config' => l(t('solrconfig.xml'), 'http://wiki.apache.org/solr/SolrConfigXml'))),
'#default_value' => $handler,
'#ahah' => array(
'path' => 'islandora/solr/process',
'wrapper' => 'solr-url',
'effect' => 'fade',
'event' => 'change',
),
);
$form['display_profiles'] = array(
'#type' => 'fieldset',
'#title' => t('Display profiles'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
// set the table form items
$form['display_profiles']['islandora_solr_primary_display_table'] = array(
'#tree' => TRUE, // this attribute is important to return the submitted values in a deeper nested arrays in
);
// get the table settings
$primary_display_array = variable_get('islandora_solr_primary_display_table', array());
$enabled = array();
// get all defined primary displays
$profiles = module_invoke_all("islandora_solr_primary_display");
if (!empty($profiles)) {
$profiles_sorted = array();
// if the table settings are set (weight), we change the order of the table rows.
if (isset($primary_display_array['weight'])) {
// new variable
$weight = $primary_display_array['weight'];
// First sort by value and then sort equal values by key: http://stackoverflow.com/a/6611077/477949
array_multisort(array_values($weight), SORT_ASC, array_keys($weight), SORT_ASC, $weight);
// Add all previously existing profiles with a weight...
foreach (array_intersect_assoc($profiles, $weight) as $key => $value) {
$profiles_sorted[$key] = $value;
}
//Account for new profiles.
foreach (array_diff_assoc($profiles, $profiles_sorted) as $key => $value) {
$profiles_sorted[$key] = $value;
}
}
// or else use the default
else {
// sort alphabetically with default on top
ksort($profiles); // only apply when there's no sort variable available.
$profiles_sorted = $profiles;
}
// table loop
foreach ($profiles_sorted as $machine_name => $profile) {
$options[$machine_name] = '';
$form['display_profiles']['islandora_solr_primary_display_table']['name'][$machine_name] = array(
'#value' => $profile['name'],
);
$form['display_profiles']['islandora_solr_primary_display_table']['machine_name'][$machine_name] = array(
'#value' => $machine_name,
);
$form['display_profiles']['islandora_solr_primary_display_table']['weight'][$machine_name] = array(
'#type' => 'weight',
'#default_value' => ($primary_display_array['weight'][$machine_name]) ? $primary_display_array['weight'][$machine_name] : 0,
'#attributes' => array('class' => 'solr-weight'),
);
$form['display_profiles']['islandora_solr_primary_display_table']['configuration'][$machine_name] = array(
'#value' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '',
);
}
$form['display_profiles']['islandora_solr_primary_display_table']['default'] = array(
'#type' => 'radios',
'#options' => $options,
'#default_value' => variable_get('islandora_solr_primary_display', 'default'),
);
$form['display_profiles']['islandora_solr_primary_display_table']['enabled'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => (!empty($primary_display_array)) ? $primary_display_array['enabled'] : $primary_display_array, // $primary_display_array['enabled'][$machine_name]
);
}
$profiles = module_invoke_all("islandora_solr_secondary_display");
ksort($profiles);
foreach ($profiles as $machine_name => $profile) {
$islandora_solr_secondary_display_options[$machine_name] = $profile['name'];
}
if (!empty($islandora_solr_secondary_display_options)) {
$form['display_profiles']['islandora_solr_secondary_display'] = array(
'#type' => 'checkboxes',
'#title' => t('Secondary Display Profiles'),
'#options' => $islandora_solr_secondary_display_options,
'#default_value' => variable_get('islandora_solr_secondary_display', array()),
'#description' => "Enabled secondary output/download types for search results.",
);
}
//Notice: Undefined index: #options in expand_checkboxes() (line 1930 of /Applications/MAMP/htdocs/drupal-6.22/includes/form.inc).
$form['dismax_allowed'] = array(
'#type' => 'hidden',
'#value' => $dismax_allowed,
);
// Display settings
$form['default_display_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Default display settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['default_display_settings']['islandora_solr_search_result_fields'] = array(
'#type' => 'textarea',
'#title' => t('Labels for Returned Fields'),
'#description' => t('Set labels for fields returned from query.
Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie <strong>dc.title ~ Title</strong>'),
'#default_value' => variable_get('islandora_solr_search_result_fields', 'dc.subject ~ Subject,dc.type ~ Type'),
'#wysiwyg' => FALSE,
);
$form['default_display_settings']['islandora_solr_search_limit_result_fields'] = array(
'#type' => 'checkbox',
'#title' => t('Limit results to fields listed above?'),
'#return_value' => 1,
'#default_value' => variable_get('islandora_solr_search_limit_result_fields', 0),
'#description' => t('If checked, results displayed will be limited to the fields specified above.<br/><strong>Note:</strong> Some display profiles may not honour this value.'),
);
$form['default_display_settings']['islandora_solr_snippet_field'] = array(
'#type' => 'textfield',
'#title' => t('Snippet Field'),
'#default_value' => variable_get('islandora_solr_snippet_field', ''),
'#description' => t("If a match is found on this field, a snippet of text will be returned, with the search term highlighted.<br />
An optional friendly label may inserted using the following pattern <strong>dsm.Text ~ Full Text</strong><br />
Use an asterisk (<strong>*</strong>) for all fields, leave blank to disable highlighting.<br />
<strong>Note:</strong><em> This feature is not supported by all display profiles.</em> "),
'#wysiwyg' => FALSE,
);
$form['default_display_settings']['islandora_solr_search_num_of_results'] = array(
'#type' => 'textfield',
'#title' => t('Results per page'),
'#size' => 5,
'#description' => t('The number of results to show per page.'),
'#default_value' => variable_get('islandora_solr_search_num_of_results', '25'),
);
$form['default_display_settings']['exposed_limit'] = array(
'#type' => 'fieldset',
'#title' => t('Exposed results per page'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['default_display_settings']['exposed_limit']['islandora_solr_search_limit_results_exposed'] = array(
'#type' => 'textfield',
'#title' => t('Exposed results per page'),
'#default_value' => variable_get('islandora_solr_search_limit_results_exposed', '10, 25, 50, 100'),
'#description' => t("Comma separated values (integers) to expose links in a block which provides the user the ability to limit search results manually.<br />
<strong>Note:</strong><em> Some display profiles might override this value.</em> "),
'#wysiwyg' => FALSE,
);
$form['default_display_settings']['exposed_limit']['islandora_solr_search_limit_results_exposed_styling'] = array(
'#type' => 'checkbox',
'#title' => t('Horizontal styling'),
'#return_value' => 1,
'#default_value' => variable_get('islandora_solr_search_limit_results_exposed_styling', 0),
'#description' => t('Styles the exposed result limit links horizontally with separators.'),
);
// Sort
$form['sort'] = array(
'#type' => 'fieldset',
'#title' => t('Sort'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['sort']['islandora_solr_search_sort_terms'] = array(
'#type' => 'textarea',
'#title' => t('Sort terms'),
'#description' => t("Indicate what fields should appear in the <strong>Islandora sort block</strong>.<br />
Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie <strong>dc.title ~ Title</strong><br />
Review the schema.xml to see what terms are available. A list of the fields available when using the schema.xml packaged with the Islandora Solr
module is available in Islandora's online documentation. <br /><strong>Important:</strong> Not all solr fields can be used for sorting. For more info, check the <a href='!sorturl' target='_blank'>solr documentation</a> on sorting.", array('!sorturl' => 'http://wiki.apache.org/solr/CommonQueryParameters#sort')),
'#default_value' => variable_get('islandora_solr_search_sort_terms', 'score ~ Relevance, PID ~ PID'),
'#wysiwyg' => FALSE,
);
// Facets
$form['facet_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Facet settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['facet_settings']['islandora_solr_search_block_facets'] = array(
'#type' => 'textarea',
'#title' => t('Facet Fields'),
'#default_value' => variable_get('islandora_solr_search_block_facets', ''),
'#description' => t("Indicate which fields will appear in the <strong>Islandora Facet Block</strong>.<br />
Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie <strong>dc.title ~ Title</strong> "),
'#default_value' => variable_get('islandora_solr_search_block_facets', 'dc.subject ~ Subject,dc.type ~ Type'),
'#wysiwyg' => FALSE,
'#default_value' => variable_get('islandora_solr_search_block_facets', 'dc.subject ~ Subject,dc.type ~ Type')
);
$form['facet_settings']['islandora_solr_search_block_facet_min_count'] = array(
'#type' => 'textfield',
'#title' => t('Minimum Results to Display Facet'),
'#size' => 5,
'#description' => t('Minimum results required to display a facet'),
'#default_value' => variable_get('islandora_solr_search_block_facet_min_count', '2'),
);
$form['facet_settings']['islandora_solr_search_block_facet_shown_limit'] = array(
'#type' => 'textfield',
'#title' => t('Initially shown facets'),
'#size' => 5,
'#description' => t('The number which should be shown initially. If there are more, then the a "Show more" button will allow the rest up to the value below to be shown. Use 0 to disable.'),
'#default_value' => variable_get('islandora_solr_search_block_facet_shown_limit', '0'),
);
$form['facet_settings']['islandora_solr_search_block_facet_limit'] = array(
'#type' => 'textfield',
'#title' => t('Maximum Facets returned'),
'#size' => 5,
'#description' => t('Set the maximum number of terms that should be returned to the user.<br />
For example, if there are 100 possible subjects in a faceted result, you may wish to return only the top 10.'),
'#default_value' => variable_get('islandora_solr_search_block_facet_limit', '20'),
);
$form['facet_settings']['islandora_facet_display_table'] = array();
$form['facet_settings']['facet_dates'] = array(
'#type' => 'fieldset',
'#title' => t('Date facets'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['facet_settings']['facet_dates']['islandora_solr_facet_date'] = array(
'#type' => 'textarea',
'#title' => t('Date field'),
'#description' => t("Indicate which date field will appear in the <strong>Islandora Facet Block</strong>.<br />
Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie <strong>dc.date ~ Date</strong> "),
'#default_value' => variable_get('islandora_solr_facet_date' , NULL),
'#wysiwyg' => FALSE,
);
$form['facet_settings']['facet_dates']['islandora_solr_facet_date_gap_variable'] = array(
'#type' => 'checkbox',
'#title' => t('Variable range gap'),
'#return_value' => 1,
'#default_value' => variable_get('islandora_solr_facet_date_gap_variable', 0),
'#description' => t('When checked, the following date range settings will be used as a default. If a date range is filtered down, a new date range gap will be calculated and applied. When unchecked the following settings provide fixed range gaps.'),
);
$form['facet_settings']['facet_dates']['islandora_solr_facet_date_start'] = array(
'#type' => 'textfield',
'#title' => t('Date start'),
'#description' => t('The lower bound for the first date range for all Date Faceting on this field. This should be a single date expression which may use the <a href="!url">DateMathParser</a> syntax.', array('!url' => 'http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html')),
'#default_value' => variable_get('islandora_solr_facet_date_start' , 'NOW/YEAR-20YEARS'),
);
$form['facet_settings']['facet_dates']['islandora_solr_facet_date_end'] = array(
'#type' => 'textfield',
'#title' => t('Date end'),
'#description' => t('The minimum upper bound for the last date range for all Date Faceting on this field. This should be a single date expression which may use the <a href="!url">DateMathParser</a> syntax.', array('!url' => 'http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html')),
'#default_value' => variable_get('islandora_solr_facet_date_end' , 'NOW'),
);
$form['facet_settings']['facet_dates']['islandora_solr_facet_date_gap'] = array(
'#type' => 'textfield',
'#title' => t('Date gap'),
'#description' => t('The size of each date range expressed as an interval to be added to the lower bound using the <a href="!url">DateMathParser</a> syntax.', array('!url' => 'http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html')),
'#default_value' => variable_get('islandora_solr_facet_date_gap' , '+1YEAR'),
);
$form['facet_settings']['facet_dates']['islandora_solr_facet_date_format'] = array(
'#type' => 'textfield',
'#title' => t('Date format'),
'#description' => t('The format of the date as it will be displayed in the facet block. Use the <a href="!url">PHP date()</a> formatting.', array('!url' => 'http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html')),
'#default_value' => variable_get('islandora_solr_facet_date_format' , 'Y'),
);
// Range slider
$form['facet_settings']['facet_dates']['range_slider'] = array(
'#type' => 'fieldset',
'#title' => t('Date range slider'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// only expose when jquery_ui is installed
if (module_exists('jquery_ui') AND jquery_ui_get_version() >= 1.7) {
$form['facet_settings']['facet_dates']['range_slider']['islandora_solr_range_slider_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable range slider'),
'#return_value' => 1,
'#default_value' => variable_get('islandora_solr_range_slider_enabled', 0),
'#description' => t('When checked, the normal range facet will be replaced by a date slider widget.'),
);
$form['facet_settings']['facet_dates']['range_slider']['islandora_solr_range_slider_color'] = array(
'#type' => 'textfield',
'#title' => t('Slider color'),
'#description' => t('A color for the range slider. Defaults to #edc240'),
'#default_value' => variable_get('islandora_solr_range_slider_color' , '#edc240'),
);
}
else {
$form['facet_settings']['facet_dates']['range_slider']['islandora_solr_date_filter_not_available'] = array(
'#type' => 'markup',
'#value' => t('The date range slider requires jQuery UI 1.7.3 or higher. Please download and enable the <a href="!jqueryupdate">jQuery Update</a> and <a href="!jqueryui">jQuery UI</a> modules and include jQuery UI 1.7.3.', array('!jqueryupdate' => 'http://drupal.org/project/jquery_update', '!jqueryui' => 'http://drupal.org/project/jquery_ui')),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
}
// Date filter
$form['facet_settings']['facet_dates']['date_filter'] = array(
'#type' => 'fieldset',
'#title' => t('Date filter'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['facet_settings']['facet_dates']['date_filter']['islandora_solr_date_filter_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable date range filter'),
'#return_value' => 1,
'#default_value' => variable_get('islandora_solr_date_filter_enabled', 0),
'#description' => t('When checked, a date range filter will become available underneath the date range facets. The date range filter includes a <em>from date</em> and a <em>to date</em> textfield. If the jquery ui module is installed and enabled, it will provide a calendar widget.'),
);
// only expose when jquery_ui is installed
if (module_exists('jquery_ui')) {
$form['facet_settings']['facet_dates']['date_filter']['islandora_solr_search_datepicker_range'] = array(
'#type' => 'textfield',
'#title' => t('Years back and forward'),
'#default_value' => variable_get('islandora_solr_search_datepicker_range', '-100:+3'),
'#size' => 10,
'#maxsize' => 10,
// @TODO: in D7 more options are possible because of jquery ui 1.8 in D7 vs 1.6 in D6
'#description' => t('Number of years to go back and forward in the datepicker popup dropdown. Values: either relative to today\'s year (-nn:+nn) or absolute (nnnn:nnnn).'),
);
}
else {
$form['facet_settings']['facet_dates']['date_filter']['islandora_solr_date_filter_not_available'] = array(
'#type' => 'markup',
'#value' => t('In order to use a calendar popup with the date filter you need to install the <a href="!jqueryui">jQuery UI</a> module.', array('!jqueryui', 'http://drupal.org/project/jquery_ui')),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
}
// Advanced search block
$form['advanced_search_block'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced search block'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['advanced_search_block']['islandora_solr_searchterms'] = array(
'#type' => 'textarea',
'#title' => t('Search Terms'),
'#description' => t("Indicate what fields should appear in the dropdown menu of terms for the <strong>Solr Advanced Search Block</strong>.<br />
Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie <strong>dc.title ~ Title</strong><br />
Review the schema.xml to see what terms are available. A list of the fields available when using the schema.xml packaged with the Islandora Solr
module is available in Islandora's online documentation."),
'#default_value' => variable_get('islandora_solr_searchterms', 'dc.title ~ Title'),
'#wysiwyg' => FALSE,
);
$form['advanced_search_block']['islandora_solr_search_block_repeat'] = array(
'#type' => 'textfield',
'#title' => t('Search Field Repetition'),
'#size' => 5,
'#description' => t('The number of fields you would like to have appear in the <strong>Solr Advanced Search Block</strong>'),
'#default_value' => variable_get('islandora_solr_search_block_repeat', '3'),
);
// Query defaults
$form['query_defaults'] = array(
'#type' => 'fieldset',
'#title' => t('Query defaults'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['query_defaults']['islandora_solr_search_namespace_restriction'] = array(
'#type' => 'textfield',
'#title' => t('Limit results to namespace'),
'#size' => 5,
'#default_value' => variable_get('islandora_solr_search_namespace_restriction', ''),
'#description' => t("Enter a namespace ie 'demo' to restrict results to PIDs within that namespace."),
);
$form['query_defaults']['islandora_solr_search_base_query'] = array(
'#type' => 'textfield',
'#title' => t('Solr Default Query'),
'#size' => 30,
'#description' => t('A default query to use to browse solr results when no explicit user query is set.
Setting a useful default query allows users to use solr to browse, without entering a query themselves.
May be used in conjunction with a background filter, below.<br>
Consider <strong><em>timestamp:[* TO NOW]</em></strong> or <strong><em>*:*</em></strong><br/>'),
'#default_value' => variable_get('islandora_solr_search_base_query', SOLR_BASE_QUERY),
);
$form['query_defaults']['islandora_solr_search_base_filter'] = array(
'#type' => 'textarea',
'#title' => t('Solr Base Filter'),
'#description' => t('Some base filters to append to all user queries -- may be used to filter results and to facilitate null-query browsing. Enter one per line. <br/>
These filters will be applied to all queries in addition to any user-selected facet filters'),
'#default_value' => variable_get('islandora_solr_search_base_filter', ''),
'#wysiwyg' => FALSE,
);
// Debug
$form['islandora_solr_search_debug_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Debug Mode?'),
'#return_value' => 1,
'#default_value' => variable_get('islandora_solr_search_debug_mode', 0),
'#description' => t('Dumps solr query to the screen for testing. Warning: if you have the Drupal Apache Solr module enabled alongside this one then the debug function will not work.'),
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Solr Configuration'),
'#weight' => 50,
);
$form['buttons']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
'#weight' => 51,
);
if (!empty($_POST) && form_get_errors()) {
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
}
$form['#submit'][] = 'solr_settings_form_submit';
//$form['#theme'] = 'system_settings_form';
$form['#theme'] = 'islandora_solr_search_admin_settings';
return ($form);
}
/**
* theme_islandora_solr_search_admin_settings()
*/
function theme_islandora_solr_search_admin_settings($form) {
$default = variable_get('islandora_solr_primary_display', 'default');
$rows = array();
//clean up facet params
// render facet display table
$facet_header = array();
$facet_header[] = $form['facet_settings']['islandora_solr_search_block_facet_min_count']['#title'];
$form['facet_settings']['islandora_solr_search_block_facet_min_count']['#title'] = NULL;
$facet_header[] = $form['facet_settings']['islandora_solr_search_block_facet_shown_limit']['#title'];
$form['facet_settings']['islandora_solr_search_block_facet_shown_limit']['#title'] = NULL;
$facet_header[] = $form['facet_settings']['islandora_solr_search_block_facet_limit']['#title'];
$form['facet_settings']['islandora_solr_search_block_facet_limit']['#title'] = NULL;
$facet_rows = array();
$facet_row = array();
$facet_row[] = array('data' => drupal_render($form['facet_settings']['islandora_solr_search_block_facet_min_count']));
$facet_row[] = array('data' => drupal_render($form['facet_settings']['islandora_solr_search_block_facet_shown_limit']));
$facet_row[] = array('data' => drupal_render($form['facet_settings']['islandora_solr_search_block_facet_limit']));
$facet_rows[] = array('data' => $facet_row);
// put the rendered table in another fieldset.
$form['facet_settings']['islandora_facet_display_table']['#type'] = 'item';
$form['facet_settings']['islandora_facet_display_table']['#title'] = t('Facet Display Settings');
$form['facet_settings']['islandora_facet_display_table']['#description'] = t('Configure how facets will be diplayed in your environment.');
$form['facet_settings']['islandora_facet_display_table']['#value'] = theme('table', $facet_header, $facet_rows, array('id' => 'solr_facet_table'));
// render islandora_solr_primary_display_table
foreach ($form['display_profiles']['islandora_solr_primary_display_table']['machine_name'] as $key => $element) {
$row = array();
// check if $key is really the array we need. we shouldn't select the #parent array for example.
if (is_array($element) && element_child($key)) {
if ($key == $default) {
$form['display_profiles']['islandora_solr_primary_display_table']['enabled'][$key]['#attributes']['disabled'] = 'disabled';
$form['display_profiles']['islandora_solr_primary_display_table']['enabled'][$key]['#value'] = TRUE;
}
$row[] = array('data' => drupal_render($form['display_profiles']['islandora_solr_primary_display_table']['default'][$key]));
$row[] = array('data' => drupal_render($form['display_profiles']['islandora_solr_primary_display_table']['enabled'][$key]), 'class' => 'advanced');
$row[] = array('data' => drupal_render($form['display_profiles']['islandora_solr_primary_display_table']['name'][$key]), 'title' => $key);
$row[] = array('data' => drupal_render($form['display_profiles']['islandora_solr_primary_display_table']['machine_name'][$key]), 'class' => 'advanced');
$row[] = array('data' => drupal_render($form['display_profiles']['islandora_solr_primary_display_table']['weight'][$key]));
$row[] = array('data' => drupal_render($form['display_profiles']['islandora_solr_primary_display_table']['configuration'][$key]), 'class' => 'advanced');
$rows[] = array('data' => $row, 'class' => 'draggable');
}
}
// Individual table headers.
// default | enabled | name | Machine readable name | weight | configuration
$header = array();
$header[] = array('data' => t('Default'));
$header[] = array('data' => t('Enabled'));
$header[] = array('data' => t('Name'));
$header[] = array('data' => t('Machine readable name'));
$header[] = array('data' => t('Weight'));
$header[] = array('data' => t('Configuration'));
// add tabledrag features
drupal_add_tabledrag('solr_config_table', 'order', 'sibling', 'solr_weight');
// put the rendered table in another fieldset.
$form['display_profiles']['islandora_solr_primary_display_table']['#type'] = 'item';
$form['display_profiles']['islandora_solr_primary_display_table']['#title'] = t('Primary Display Profiles');
$form['display_profiles']['islandora_solr_primary_display_table']['#description'] = t('Preferred normal display profile for search results. These may be provided by third-party modules.');
$form['display_profiles']['islandora_solr_primary_display_table']['#value'] = theme('table', $header, $rows, array('id' => 'solr-primary-display-table'));
// render form
$output = '';
$output .= drupal_render($form);
// add tabledrag features
drupal_add_tabledrag('solr-primary-display-table', 'order', 'sibling', 'solr-weight');
return $output;
}
/**
*
* @param String $solr_url
* @return boolean
*
* Checks availability of Solr installation
*
*/
function solr_available($solr_url) {
$handle = curl_init($solr_url . '/admin/ping');
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$retval = ((int)($httpCode / 100) === 2);
curl_close($handle);
return $retval;
}
/**
* get handlers??
* @param String $solr_url
* @return array
*/
function get_handlers($solr_url) {
$url = $solr_url . '/admin/file/?file=solrconfig.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$xml = simplexml_load_string(curl_exec($ch));
foreach ($xml->requestHandler as $handler) {
if ($handler['class'] == 'solr.SearchHandler') {
$handlerName = (string) $handler['name'];
$slashed = preg_match('/^\//', $handlerName);
if ($handlerName != 'dismax' && $handlerName != 'partitioned' & !$slashed) {
$handlers[$handlerName] = $handlerName;
}
}
}
return $handlers;
}
/**
* Checks url validity and refreshes requestHandler dropdown list
*/
function update_solr_url_div() {
$form = callback_prep();
$changed_elements = $form['solr_ahah_wrapper'];
unset($changed_elements['#prefix'], $changed_elements['#suffix']);
$output = theme('status_messages') . drupal_render($changed_elements);
drupal_json(array(
'status' => TRUE,
'data' => $output,
));
}
/**
* callback prep ??
* @return array
* Utilty function to prep $form_state for ahah
*/
function callback_prep() {
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = check_plain($_POST['form_build_id']);
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
// Enable the submit/validate handlers to determine whether AHAH-submittted.
$form_state['ahah_submission'] = TRUE;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
return $form;
}
/**
* Form validator
* @param array $form
* @param array $form_state
*/
function islandora_solr_admin_settings_validate($form, &$form_state) {
$form_state['values']['islandora_solr_search_namespace_restriction'] = preg_replace('/:$/', '', $form_state['values']['islandora_solr_search_namespace_restriction']);
$limit_results_exposed = explode(',', $form_state['values']['islandora_solr_search_limit_results_exposed']);
foreach ($limit_results_exposed as $limit) {
$limit = trim($limit);
if (!is_numeric($limit)) {
form_set_error('islandora_solr_search_limit_results_exposed', t('Exposed results must be numeric.'));
}
if (strpos($limit, '.') OR strpos($limit, ',')) {
form_set_error('islandora_solr_search_limit_results_exposed', t('Exposed results cannot be decimals.'));
}
}
}
/**
* Solr settings from submit
* @param array $form
* @param array $form_state
* @return NULL
*/
function solr_settings_form_submit($form, &$form_state) {
// old_default variable
$old_default = variable_get('islandora_solr_primary_display', 'default');
// new_default variable
$new_default = $form_state['values']['islandora_solr_primary_display_table']['default'];
// make default enabled
$form_state['values']['islandora_solr_primary_display_table']['enabled'][$new_default] = $new_default;
$form_state['values']['islandora_solr_primary_display_table']['enabled'][$old_default] = $old_default;
variable_set('islandora_solr_primary_display', $new_default);
if ($form_state['clicked_button']['#id'] != 'edit-submit') {
$form_state['rebuild'] = TRUE;
return;
}
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
// Exclude unnecessary elements.
unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']);
foreach ($form_state['values'] as $key => $value) {
if ($op == t('Reset to defaults')) {
variable_del($key);
}
else {
if (is_array($value) && isset($form_state['values']['array_filter'])) {
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
}
}
if ($op == t('Reset to defaults')) {
drupal_set_message(t('The configuration options have been reset to their default values.'));
}
else {
drupal_set_message(t('The solr configuration options have been saved.'));
}
cache_clear_all();
drupal_rebuild_theme_registry();
}
/**
* Solr admin refresh
* @param type $form
* @param array $form_state
*/
function solr_admin_refresh($form, &$form_state) {
$values = $form_state['values'];
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$form_state['rebuild'] = TRUE;
}
/**
* Checks for dismax
* @param type $solr_url
* @param type $selected_handler
* @return boolean
*/
function check_dismax($solr_url, $selected_handler) {
$dismax = FALSE;
$url = $solr_url . '/admin/file/?file=solrconfig.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$xml = simplexml_load_string(curl_exec($ch));
foreach ($xml->requestHandler as $handler) {
if ($handler['class'] == 'solr.SearchHandler') {
if ((string) $handler['name'] == $selected_handler) {
foreach ($handler->lst as $first) {
foreach ($first->str as $str) {
if ($str['name'] == 'qf') {
$dismax = TRUE;
}
}
}
}
}
}
return $dismax;
}