forked from Islandora/islandora_solr_search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_solr_search.module
213 lines (188 loc) · 9.54 KB
/
islandora_solr_search.module
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
<?php
global $islandora_query;
/**
* @file
* Implementation of Solr search for the Islandora fedora_search module.
*/
/**
* Implementation of hook_menu().
*/
function islandora_solr_search_menu() {
$items['islandora/solr/search'] = array(
'page callback' => 'islandora_solr_search',
'access arguments' => array('view fedora collection'), //depends of fedora_repository view
'type' => MENU_CALLBACK,
);
$items['admin/settings/islandora_solr_search'] = array(
'title' => 'Islandora Solr Client',
'description' => 'Managing Islandora Solr Searching',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_solr_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'solr.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implementation of hook_block().
*/
function islandora_solr_search_block($op = 'list', $delta = 0, $edit = array()) {
// The $op parameter determines what piece of information is being requested.
switch ($op) {
case 'list':
// If $op is "list", we just need to return a list of block descriptions.
// This is used to provide a list of possible blocks to the administrator,
// end users will not see these descriptions.
$blocks[0] = array(
'info' => t('Islandora Solr Search Block'),
);
$blocks[1] = array(
'info' => t('Islandora Solr Facet Block'),
);
$blocks[2] = array(
'info' => t('Islandora Solr Simple Search Block'),
);
return $blocks;
case 'configure':
// If $op is "configure", we need to provide the administrator with a
// configuration form. The $delta parameter tells us which block is being
// configured. In this example, we'll allow the administrator to customize
// the text of the first block.
$form = array();
return $form;
case 'save':
// If $op is "save", we need to save settings from the configuration form.
// Since the first block is the only one that allows configuration, we
// need to check $delta to make sure we only save it.
case 'view': default:
// If $op is "view", then we need to generate the block for display
// purposes. The $delta parameter tells us which block is being requested.
switch ($delta) {
case 0:
$block['subject'] = t('Islandora Solr Search');
// The content of the block is typically generated by calling a custom
// function.
$block['content'] = drupal_get_form('islandora_solr_search_block_form');
break;
case 1:
// The subject is displayed at the top of the block. Note that it
// should be passed through t() for translation.
$block['subject'] = t('Islandora Facet Block');
// The content of the block is typically generated by calling a custom
// function.
require_once(drupal_get_path('module', 'islandora_solr_search') . '/IslandoraSolrResults.inc');
$solrResults = new IslandoraSolrResults();
$block['content'] = $solrResults->displayFacets();
break;
case 2:
$block['subject'] = t('Islandora Solr Simple Search');
$block['content'] = drupal_get_form('islandora_solr_simple_search_form');
break;
}
return $block;
}
}
/**
* Implementation of hook_theme().
*/
function islandora_solr_search_theme() {
return array(
'islandora_solr_search_block_form' => array(
'arguments' => array(
'form' => NULL,
),
),
);
}
function islandora_solr_simple_search_form() {
module_load_include('inc', 'islandora_solr_search', 'IslandoraSolrResults');
$searchClass = new IslandoraSolrResults();
return $searchClass->build_simple_solr_form();
}
function islandora_solr_simple_search_form_validate($form, &$form_state) {
if ($form_state['values']['islandora_simple_search_query'] == '') {
form_set_error('islandora_simple_search_query', t('The Search field cannot be empty.'));
}
}
function islandora_solr_simple_search_form_submit($form, &$form_state) {
$searchString = $form_state['values']['islandora_simple_search_query'];
//$searchString = drupal_urlencode($searchString);
$searchString = htmlspecialchars(drupal_urlencode($searchString), ENT_QUOTES, 'utf-8', false);
$searchString = str_replace('/', '~slsh~', $searchString); //replace the slash so url doesn't break
drupal_goto("islandora/solr/search/$searchString/1/-/dismax");
}
function islandora_solr_search_block_form() {
global $islandora_query;
module_load_include('inc', 'islandora_solr_search', 'IslandoraSolrResults');
$searchClass = new IslandoraSolrResults();
return $searchClass->build_solr_search_form(null, null, $islandora_query);
}
function theme_islandora_solr_search_block_form($form) {
drupal_add_css(drupal_get_path('module', 'islandora_solr_search') . '/islandora_solr_search.css');
module_load_include('inc', 'islandora_solr_search', 'IslandoraSolrResults');
$advanced_search_form = new IslandoraSolrResults();
return $advanced_search_form->theme_solr_search_form($form);
}
function islandora_solr_search($query, $startPage = 1, $fq=null, $dismax=null) {
global $islandora_query;
$islandora_query = $query;
module_load_include('inc', 'islandora_solr_search', 'IslandoraSolrResults');
$searchClass = new IslandoraSolrResults();
return $searchClass->searchAndDisplay($query, $startPage, $fq, $dismax);
}
function islandora_solr_search_block_form_submit($form, &$form_state) {
require_once(drupal_get_path('module', 'islandora_solr_search') . '/IslandoraSolrResults.inc');
$type_id = trim($form_state['values']['type']);
$repeat = variable_get('islandora_solr_search_block_repeat', t('3'));
$searchString = trim($form_state['values']['type1']) . ':(' . IslandoraSolrResults::lesser_escape(trim($form_state['values']['fedora_terms1'])) . ')';
if ($form_state['values']['fedora_terms2'] != '') {
$searchString .=' ' . trim($form_state['values']['andor1']) . ' ' . trim($form_state['values']['type2']) . ':(' . IslandoraSolrResults::lesser_escape(trim($form_state['values']['fedora_terms2'])) . ')';
}
if ($repeat > 2 && $repeat < 9) {
for ($i = 3; $i < $repeat + 1; $i++) {
$t = $i - 1;
if ($form_state['values']["fedora_terms$i"] != '') {
$searchString .= ' ' . trim($form_state['values']["andor$t"]) . ' ' . trim($form_state['values']["type$i"]) . ':(' . IslandoraSolrResults::lesser_escape(trim($form_state['values']["fedora_terms$i"])) . ')';
}
}
}
$searchString = htmlspecialchars(drupal_urlencode($searchString), ENT_QUOTES, 'utf-8', false);
$searchString = str_replace('/', '~slsh~', $searchString); //replace the slash so url doesn't break
drupal_goto("islandora/solr/search/$searchString/1");
}
/**
* Implementation of hook_help().
*/
function islandora_solr_search_help($path, $arg) {
switch ($path) {
case 'admin/help#islandora_solr_search':
return t(
'<p>
The Islandora Solr Search extends the functionality of the Fedora_Repository module.
This module allows one or more of a series of blocks to be configured to search a solr index.
This module can co-exist with the original Fedora_Repositories search block, but Solr\'s
additional functionality will normally make the original block redundant.
</p>
<p>
The !guide contains additonal information.
</p>
<ul>
<li>Islandora Solr Search requires a working Solr instance. The !sWiki has full setup instructions</li>
<li>Once Solr is running and tested, configure <b>Gsearch</b> to update Solr. Consult the !GSearch for details.</li>
<li>Retreive the !client, unzip it, and copy the <b>Solr</b> directory from the archive to the islandora_solr_search module\'s folder.</li>
<li>Go to Administer > Site Configuration > Islandora Solr Client <em>(or click the link below)</em> to configure the module. Set which Solr request handler to use, set the port, host and context for the index to be queried, and select which fields are to be used for filtering. Solr\'s <b>schema.xml</b> and <b>solrconfig.xml</b> must be configured for the request handler as well as which fields to index and return.</li>
<li>The module allows custom code to be used to display search results. If custom PHP code is used, the paths to that codes\'s file and function must be entered here as well.</li>
<li>Three different blocks are now available under Administer > Site Building > Blocks: Islandora Solr Simple Search Block, Islandora Solr Facet Block, and Islandora Solr Search Block. The configuration setting for each of these blocks will allow you to control their position on the screen, and on which pages they will be displayed.</li>
<li>The Islandora Solr Simple Search Block will use will add defType=dismax to the configured request handler. The request handler tag in <b>solrconfig.xml</b> must have an attribute of <b>default="true"</b>.</li>
</ul>
',
array(
'!guide' => l('Islandora Guide','https://wiki.duraspace.org/display/ISLANDORA/Islandora+Guide'),
'!sWiki' => l("Solr Wiki", 'http://wiki.apache.org/solr/SolrTomcat'),
'!GSearch' => l('GSearch Documentation', 'https://wiki.duraspace.org/display/FCSVCS/Generic+Search+Service+2.2'),
'!client' => l('Apache Solr php client', 'http://code.google.com/p/solr-php-client'),
)
);
}
}