0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 * @file
|
|
5 * Administrative settings for searching.
|
|
6 */
|
|
7
|
|
8 /**
|
|
9 * Helper function for empty search configuration.
|
|
10 */
|
|
11 function _apachesolr_search_browse_form($default_value) {
|
|
12 $description = t('This is what is shown when the user enters an empty search, or removes all filters from an active search.') . ' ';
|
|
13 if (!module_exists('facetapi')) {
|
|
14 $description .= t('<strong>Facets will not be shown until you enable Facet API module.</strong>');
|
|
15 }
|
|
16 else {
|
|
17 $description .= t('Remember to configure the facets on the <a href="!facetslink">search environment page</a> and assign blocks to regions on the <a href="!blocklink">block settings page</a>', array(
|
|
18 '!facetslink' => url('admin/config/search/apachesolr/settings/'),
|
|
19 '!blocklink' => url('admin/structure/block'),
|
|
20 ));
|
|
21 }
|
|
22 return array(
|
|
23 '#type' => 'radios',
|
|
24 '#title' => t('Behavior on empty search'),
|
|
25 '#options' => array(
|
|
26 'none' => t("Show search box"),
|
|
27 'browse' => t("Show enabled facets' blocks under the search box"),
|
|
28 'blocks' => t("Show enabled facets' blocks in their configured regions"),
|
|
29 'results' => t("Show enabled facets' blocks in their configured regions and first page of all available results"),
|
|
30 ),
|
|
31 '#default_value' => $default_value,
|
|
32 '#description' => $description,
|
|
33 );
|
|
34 }
|
|
35
|
|
36 /**
|
|
37 * Menu callback for the overview page showing custom search pages and blocks.
|
|
38 * @return array $build
|
|
39 */
|
|
40 function apachesolr_search_page_list_all() {
|
|
41 $build['pages'] = apachesolr_search_page_list_pages();
|
|
42 $build['blocks'] = apachesolr_search_page_list_blocks();
|
|
43 return $build;
|
|
44
|
|
45 }
|
|
46
|
|
47 /**
|
|
48 * Listing of all the search pages
|
|
49 * @return array $build
|
|
50 */
|
|
51 function apachesolr_search_page_list_pages() {
|
|
52 $build = array();
|
|
53 $rows = array();
|
|
54 $rows['core_search'] = array();
|
|
55
|
|
56 // Build the sortable table header.
|
|
57 $header = array(
|
|
58 'label' => array('data' => t('Name'), 'field' => 's.label'),
|
|
59 'path' => array('data' => t('Path'), 'field' => 's.search_path'),
|
|
60 'environment' => array('data' => t('Search environment')),
|
|
61 'operations' => array('data' => t('Operations')),
|
|
62 );
|
|
63
|
|
64 $search_pages = apachesolr_search_load_all_search_pages();
|
|
65 $default_search_page = apachesolr_search_default_search_page();
|
|
66 foreach ($search_pages as $search_page) {
|
|
67 $row = array();
|
|
68
|
|
69 // Add the label
|
|
70 $label = check_plain($search_page['label']);
|
|
71 // Is this row our default environment?
|
|
72 if ($search_page['page_id'] == $default_search_page) {
|
|
73 $label = t('!search_page <em>(Default)</em>', array('!search_page' => $label));
|
|
74 }
|
|
75
|
|
76 $row[] = $label;
|
|
77 // Add the link
|
|
78 $row[] = array(
|
|
79 'data' => array(
|
|
80 '#type' => 'link',
|
|
81 '#title' => $search_page['search_path'],
|
|
82 '#href' => $search_page['search_path'],
|
|
83 ),
|
|
84 );
|
|
85
|
|
86 // Add the search environment
|
|
87 $environment = apachesolr_environment_load($search_page['env_id']);
|
|
88 $row[] = $environment ? check_plain($environment['name']) : check_plain(t('<Disabled>'));
|
|
89 // Operations
|
|
90 $row[] = array('data' => l(t('Edit'), 'admin/config/search/apachesolr/search-pages/' . $search_page['page_id'] . '/edit'));
|
|
91 $row[] = array('data' => l(t('Clone'), 'admin/config/search/apachesolr/search-pages/' . $search_page['page_id'] . '/clone'));
|
|
92
|
|
93 // Allow to revert a search page or to delete it
|
|
94 if (!isset($search_page['settings']['apachesolr_search_not_removable']) && !isset($search_page['in_code_only'])) {
|
|
95 if ((isset($search_page['type']) && $search_page['type'] == 'Overridden')) {
|
|
96 $row[] = array('data' => l(t('Revert'), 'admin/config/search/apachesolr/search-pages/' . $search_page['page_id'] . '/delete'));
|
|
97 } else {
|
|
98 $row[] = array('data' => l(t('Delete'), 'admin/config/search/apachesolr/search-pages/' . $search_page['page_id'] . '/delete'));
|
|
99 }
|
|
100 }
|
|
101 else {
|
|
102 $row[] = '';
|
|
103 }
|
|
104 $rows[$search_page['page_id']] = $row;
|
|
105 }
|
|
106
|
|
107 // Automatically enlarge our header with the operations size
|
|
108 $header['operations']['colspan'] = count(reset($rows)) - 3;
|
|
109
|
|
110 $build['list'] = array(
|
|
111 '#prefix' => '<h3>Pages</h3>',
|
|
112 '#theme' => 'table',
|
|
113 '#header' => $header,
|
|
114 '#rows' => array_values($rows),
|
|
115 '#empty' => t('No available search pages.'),
|
|
116 );
|
|
117 $build['pager'] = array(
|
|
118 '#theme' => 'pager',
|
|
119 '#quantity' => 20,
|
|
120 '#weight' => 10,
|
|
121 );
|
|
122
|
|
123 return $build;
|
|
124 }
|
|
125
|
|
126 /**
|
|
127 * Listing of all the search blocks
|
|
128 * @return array $build
|
|
129 */
|
|
130 function apachesolr_search_page_list_blocks() {
|
|
131 $build = array();
|
|
132 $rows = array();
|
|
133
|
|
134 // Build the sortable table header.
|
|
135 $header = array(
|
|
136 'label' => array('data' => t('Name'), 'field' => 's.label'),
|
|
137 'environment' => array('data' => t('Search environment')),
|
|
138 'operations' => array('data' => t('Operations')),
|
|
139 );
|
|
140
|
|
141 $search_blocks = variable_get('apachesolr_search_mlt_blocks', array());
|
|
142 foreach ($search_blocks as $search_block_id => $search_block) {
|
|
143 $row = array();
|
|
144
|
|
145 // Add the label
|
|
146 $label = check_plain($search_block['name']);
|
|
147 $row[] = $label;
|
|
148
|
|
149 // Add the search environment
|
|
150 $environment = apachesolr_environment_load($search_block['mlt_env_id']);
|
|
151 $row[] = $environment ? check_plain($environment['name']) : check_plain(t('<Disabled>'));
|
|
152 // Operations
|
|
153 if (module_exists('block')) {
|
|
154 $row[] = array('data' => l(t('Configure'), 'admin/structure/block/manage/apachesolr_search/' . $search_block_id . '/configure', array('query' => array('destination' => current_path()))));
|
|
155 }
|
|
156 $row[] = array('data' => l(t('Delete'), 'admin/config/search/apachesolr/search-pages/block/' . $search_block_id . '/delete'));
|
|
157 $rows[$search_block_id] = $row;
|
|
158 }
|
|
159
|
|
160 // Automatically enlarge our header with the operations size
|
|
161 $header['operations']['colspan'] = count(reset($rows)) - 2;
|
|
162
|
|
163 $build['list'] = array(
|
|
164 '#prefix' => '<h3>Blocks "More Like This"</h3>',
|
|
165 '#theme' => 'table',
|
|
166 '#header' => $header,
|
|
167 '#rows' => array_values($rows),
|
|
168 '#empty' => t('No available search blocks.'),
|
|
169 );
|
|
170 $build['pager'] = array(
|
|
171 '#theme' => 'pager',
|
|
172 '#quantity' => 20,
|
|
173 '#weight' => 10,
|
|
174 );
|
|
175
|
|
176 return $build;
|
|
177 }
|
|
178
|
|
179 /**
|
|
180 * Menu callback/form-builder for the form to create or edit a search page.
|
|
181 */
|
|
182 function apachesolr_search_page_settings_form($form, &$form_state, $search_page = NULL) {
|
|
183 $environments = apachesolr_load_all_environments();
|
|
184 $options = array('' => t('<Disabled>'));
|
|
185 foreach ($environments as $id => $environment) {
|
|
186 $options[$id] = $environment['name'];
|
|
187 }
|
|
188 // Validate the env_id.
|
|
189 if (!empty($search_page['env_id']) && !apachesolr_environment_load($search_page['env_id'])) {
|
|
190 $search_page['env_id'] = '';
|
|
191 }
|
|
192
|
|
193 // Initializes form with common settings.
|
|
194 $form['search_page'] = array(
|
|
195 '#type' => 'value',
|
|
196 '#value' => $search_page,
|
|
197 );
|
|
198
|
|
199 $form['label'] = array(
|
|
200 '#type' => 'textfield',
|
|
201 '#title' => t('Label'),
|
|
202 '#description' => '',
|
|
203 '#required' => TRUE,
|
|
204 '#size' => 30,
|
|
205 '#maxlength' => 32,
|
|
206 '#default_value' => !empty($search_page['label']) ? $search_page['label'] : '',
|
|
207 '#description' => t('The human-readable name of the search page configuration.'),
|
|
208 );
|
|
209
|
|
210 $form['page_id'] = array(
|
|
211 '#type' => 'machine_name',
|
|
212 '#maxlength' => 32,
|
|
213 '#required' => TRUE,
|
|
214 '#machine_name' => array(
|
|
215 'exists' => 'apachesolr_search_page_exists',
|
|
216 'source' => array('label'),
|
|
217 ),
|
|
218 '#description' => '',
|
|
219 '#default_value' => !empty($search_page['page_id']) ? $search_page['page_id'] : '',
|
|
220 '#disabled' => !empty($search_page),
|
|
221 '#description' => t('A unique machine-readable identifier for the search page configuration. It must only contain lowercase letters, numbers, and underscores.'),
|
|
222 );
|
|
223
|
|
224 $form['description_enable'] = array(
|
|
225 '#type' => 'checkbox',
|
|
226 '#title' => t('Description'),
|
|
227 '#default_value' => !empty($search_page['description']) ? TRUE : FALSE
|
|
228 );
|
|
229
|
|
230 $form['description'] = array(
|
|
231 '#type' => 'textfield',
|
|
232 '#title' => t('Provide description'),
|
|
233 '#title_display' => 'invisible',
|
|
234 '#size' => 64,
|
|
235 '#default_value' => !empty($search_page['description']) ? $search_page['description'] : '',
|
|
236 '#dependency' => array(
|
|
237 'edit-description-enable' => array(1),
|
|
238 ),
|
|
239 );
|
|
240
|
|
241 $is_default = FALSE;
|
|
242 if (!empty($search_page)) {
|
|
243 $is_default = $search_page['page_id'] == apachesolr_search_default_search_page();
|
|
244 }
|
|
245 $form['make_default'] = array(
|
|
246 '#type' => 'checkbox',
|
|
247 '#title' => t('Make this Solr Search Page the default'),
|
|
248 '#description' => t('Useful for eg. making facets to link to this page when they are shown on non-search pages'),
|
|
249 '#default_value' => $is_default,
|
|
250 '#disabled' => $is_default,
|
|
251 );
|
|
252
|
|
253 $form['info'] = array(
|
|
254 '#title' => t('Search Page Information'),
|
|
255 '#type' => 'fieldset',
|
|
256 '#collapsible' => FALSE,
|
|
257 '#prefix' => '<div id="dynamic-search-page">',
|
|
258 '#suffix' => '</div>',
|
|
259 );
|
|
260
|
|
261 $core_search = FALSE;
|
|
262 if (!empty($search_page['page_id']) && ($search_page['page_id'] == 'core_search')) {
|
|
263 $core_search = TRUE;
|
|
264 }
|
|
265 if ($core_search) {
|
|
266 $description = t('This page always uses the current default search environment');
|
|
267 }
|
|
268 else {
|
|
269 $description = t('The environment that is used by this search page. If no environment is selected, this page will be disabled.');
|
|
270 }
|
|
271
|
|
272 $form['info']['env_id'] = array(
|
|
273 '#title' => t('Search environment'),
|
|
274 '#type' => 'select',
|
|
275 '#options' => $options,
|
|
276 '#default_value' => !empty($search_page['env_id']) ? $search_page['env_id'] : '',
|
|
277 '#disabled' => $core_search,
|
|
278 '#description' => $description,
|
|
279 );
|
|
280
|
|
281 $form['info']['page_title'] = array(
|
|
282 '#title' => t('Title'),
|
|
283 '#type' => 'textfield',
|
|
284 '#required' => TRUE,
|
|
285 '#maxlength' => 255,
|
|
286 '#description' => 'You can use %value to place the search term in the title',
|
|
287 '#default_value' => !empty($search_page['page_title']) ? $search_page['page_title'] : '',
|
|
288 );
|
|
289
|
|
290 $search_types = apachesolr_search_load_all_search_types();
|
|
291 $options = array('custom' => t('Custom Field'));
|
|
292 foreach ($search_types as $id => $search_type) {
|
|
293 $options[$id] = $search_type['name'];
|
|
294 }
|
|
295
|
|
296 $form['info']['search_type'] = array(
|
|
297 '#title' => t('Search Type'),
|
|
298 '#type' => 'select',
|
|
299 '#options' => $options,
|
|
300 '#default_value' => !empty($search_page['settings']['apachesolr_search_search_type']) ? $search_page['settings']['apachesolr_search_search_type'] : '',
|
|
301 '#access' => !$core_search,
|
|
302 '#description' => t('Use this only when filtering on a value from the search path.
|
|
303 For example, select Taxonomy Term to filter on a term ID (search/taxonomy/%).'),
|
|
304 '#ajax' => array(
|
|
305 'callback' => 'apachesolr_search_ajax_search_page_default',
|
|
306 'wrapper' => 'dynamic-search-page',
|
|
307 'method' => 'replace',
|
|
308 ),
|
|
309 );
|
|
310
|
|
311 // Token element validate is added to validate the specific
|
|
312 // tokens that are allowed
|
|
313 $form['info']['search_path'] = array(
|
|
314 '#title' => t('Path'),
|
|
315 '#type' => 'textfield',
|
|
316 '#required' => TRUE,
|
|
317 '#maxlength' => 255,
|
|
318 '#description' => t('For example: search/my-search-page. Search keywords will appear at the end of the path.'),
|
|
319 '#default_value' => !empty($search_page['search_path']) ? $search_page['search_path'] : '',
|
|
320 );
|
|
321 if (!$core_search) {
|
|
322 $form['info']['search_path']['#description'] .= ' ' . t('You can use one % to make the search page dynamic.');
|
|
323 }
|
|
324
|
|
325 $form['info']['custom_filter_enable'] = array(
|
|
326 '#type' => 'checkbox',
|
|
327 '#title' => t('Custom Filter'),
|
|
328 '#default_value' => !empty($search_page['settings']['apachesolr_search_custom_enable']) ? TRUE : FALSE
|
|
329 );
|
|
330
|
|
331 $form['info']['filters'] = array(
|
|
332 '#title' => t('Custom filters'),
|
|
333 '#type' => 'textfield',
|
|
334 '#required' => FALSE,
|
|
335 '#maxlength' => 255,
|
|
336 '#description' => t('A comma-separated list of lucene filter queries to apply by default.'),
|
|
337 '#default_value' => !empty($search_page['settings']['fq']) ? implode(', ', $search_page['settings']['fq']) : '',
|
|
338 '#dependency' => array(
|
|
339 'edit-custom-filter-enable' => array(1),
|
|
340 'edit-search-type' => array('custom'),
|
|
341 ),
|
|
342 );
|
|
343 if (!$core_search) {
|
|
344 $form['info']['filters']['#description'] .= ' ' . t('E.g. "bundle:blog, is_uid:(1 OR 2 OR %). % will be replaced by the value of % in the path"');
|
|
345 }
|
|
346
|
|
347 $form['advanced'] = array(
|
|
348 '#title' => t('Advanced Search Page Options'),
|
|
349 '#type' => 'fieldset',
|
|
350 '#collapsible' => TRUE,
|
|
351 '#collapsed' => TRUE,
|
|
352 '#tree' => TRUE,
|
|
353 );
|
|
354
|
|
355 // Results per page per search page
|
|
356 $default_value = isset($search_page['settings']['apachesolr_search_per_page']) ? $search_page['settings']['apachesolr_search_per_page'] : '10';
|
|
357 $form['advanced']['apachesolr_search_per_page'] = array(
|
|
358 '#type' => 'textfield',
|
|
359 '#size' => 3,
|
|
360 '#title' => t('Results per page'),
|
|
361 '#description' => t('How many items will be displayed on one page of the search result.'),
|
|
362 '#default_value' => $default_value,
|
|
363 );
|
|
364
|
|
365 // Enable/disable spellcheck on pages
|
|
366 $default_value = isset($search_page['settings']['apachesolr_search_spellcheck']) ? $search_page['settings']['apachesolr_search_spellcheck'] : TRUE;
|
|
367 $form['advanced']['apachesolr_search_spellcheck'] = array(
|
|
368 '#type' => 'checkbox',
|
|
369 '#title' => t('Enable spell check'),
|
|
370 '#description' => t('Display "Did you mean … ?" above search results.'),
|
|
371 '#default_value' => $default_value,
|
|
372 );
|
|
373
|
|
374 // Enable/disable search form on search page (replaced by a block perhaps)
|
|
375 $default_value = isset($search_page['settings']['apachesolr_search_search_box']) ? $search_page['settings']['apachesolr_search_search_box'] : TRUE;
|
|
376 $form['advanced']['apachesolr_search_search_box'] = array(
|
|
377 '#type' => 'checkbox',
|
|
378 '#title' => t('Enable the search box on the page'),
|
|
379 '#description' => t('Display a search box on the page.'),
|
|
380 '#access' => !$core_search,
|
|
381 '#default_value' => $default_value,
|
|
382 );
|
|
383
|
|
384 // Enable/disable search form on search page (replaced by a block perhaps)
|
|
385 $default_value = isset($search_page['settings']['apachesolr_search_allow_user_input']) ? $search_page['settings']['apachesolr_search_allow_user_input'] : FALSE;
|
|
386 $form['advanced']['apachesolr_search_allow_user_input'] = array(
|
|
387 '#type' => 'checkbox',
|
|
388 '#title' => t('Allow user input using the URL'),
|
|
389 '#description' => t('Allow users to use the URL for manual facetting via fq[] params (e.g. http://example.com/search/site/test?fq[]=uid:1&fq[]=tid:99). This will only work in combination with a keyword search. The recommended value is unchecked'),
|
|
390 '#default_value' => $default_value,
|
|
391 );
|
|
392
|
|
393 // Use the main search page setting as the default for new pages.
|
|
394 $default_value = isset($search_page['settings']['apachesolr_search_browse']) ? $search_page['settings']['apachesolr_search_browse'] : 'browse';
|
|
395 $form['advanced']['apachesolr_search_browse'] = _apachesolr_search_browse_form($default_value);
|
|
396
|
|
397 // Button for the corresponding actions
|
|
398 $form['actions'] = array(
|
|
399 '#type' => 'actions',
|
|
400 );
|
|
401
|
|
402 $form['actions']['submit'] = array(
|
|
403 '#type' => 'submit',
|
|
404 '#redirect' => 'admin/config/search/apachesolr/search-pages',
|
|
405 '#value' => t('Save'),
|
|
406 );
|
|
407 $form['actions']['submit_edit'] = array(
|
|
408 '#type' => 'submit',
|
|
409 '#value' => t('Save and edit'),
|
|
410 );
|
|
411
|
|
412 $form['actions']['cancel'] = array(
|
|
413 '#type' => 'link',
|
|
414 '#title' => t('Cancel'),
|
|
415 '#href' => 'admin/config/search/apachesolr/search-pages',
|
|
416 );
|
|
417
|
|
418 $form['#submit'][] = 'apachesolr_search_page_settings_form_submit';
|
|
419
|
|
420 return $form;
|
|
421 }
|
|
422
|
|
423 /**
|
|
424 * Callback element needs only select the portion of the form to be updated.
|
|
425 * Since #ajax['callback'] return can be HTML or a renderable array (or an
|
|
426 * array of commands), we can just return a piece of the form.
|
|
427 */
|
|
428 function apachesolr_search_ajax_search_page_default($form, $form_state, $search_page = NULL) {
|
|
429
|
|
430 $search_page = $form_state['values']['search_page'];
|
|
431 $search_types = apachesolr_search_load_all_search_types();
|
|
432
|
|
433 // Helping with sensible defaults for the search path
|
|
434 $default_search_path = '';
|
|
435 if (!empty($form_state['values']['search_type']) && $form_state['values']['search_type'] != 'custom') {
|
|
436 $default_search_path = $search_types[$form_state['values']['search_type']]['default menu'];
|
|
437 $form['info']['search_path']['#value'] = $default_search_path;
|
|
438 }
|
|
439
|
|
440 // Helping with sensible defaults for the search title
|
|
441 $default_search_title = '';
|
|
442
|
|
443 if (empty($form_state['values']['page_title']) && $form_state['values']['search_type'] != 'custom') {
|
|
444 $default_search_title_callback = $search_types[$form_state['values']['search_type']]['title callback'];
|
|
445 $default_search_title = $default_search_title_callback();
|
|
446 $form['info']['page_title']['#value'] = $default_search_title;
|
|
447 }
|
|
448 return $form['info'];
|
|
449 }
|
|
450
|
|
451 function apachesolr_search_page_settings_form_validate($form, &$form_state) {
|
|
452 // Performs basic validation of the menu path.
|
|
453 if (url_is_external($form_state['values']['search_path'])) {
|
|
454 form_set_error('search_path', t('Path must be local.'));
|
|
455 }
|
|
456 $form_state['values']['search_path'] = trim($form_state['values']['search_path'], '/');
|
|
457 if (empty($form_state['values']['search_path'])) {
|
|
458 form_set_error('search_path', t('Path required.'));
|
|
459 }
|
|
460 if (!is_numeric($form_state['values']['advanced']['apachesolr_search_per_page'])) {
|
|
461 form_set_error('advanced][apachesolr_search_per_page', t('The amount of search results must be an integer.'));
|
|
462 }
|
|
463 $form_state['values']['advanced']['apachesolr_search_per_page'] = (int) $form_state['values']['advanced']['apachesolr_search_per_page'];
|
|
464 if (empty($form_state['values']['advanced']['apachesolr_search_per_page'])) {
|
|
465 form_set_error('advanced][apachesolr_search_per_page', t('The amount of search results cannot be empty.'));
|
|
466 }
|
|
467 if ($form_state['values']['page_id'] == 'core_search') {
|
|
468 if (!preg_match('@^search/[^/%]+$@', $form_state['values']['search_path'])) {
|
|
469 form_set_error('search_path', t('The core Search page path must start with search/ and only have one /'));
|
|
470 }
|
|
471 }
|
|
472 elseif (count(explode('%', $form_state['values']['search_path'])) > 2) {
|
|
473 form_set_error('search_path', t('Only one % placeholder is allowed.'));
|
|
474 }
|
|
475 }
|
|
476
|
|
477 /**
|
|
478 * Processes apachesolr_search_page_settings_form form submissions.
|
|
479 */
|
|
480 function apachesolr_search_page_settings_form_submit($form, &$form_state) {
|
|
481 $settings = array();
|
|
482 $settings['fq'] = array();
|
|
483 if ($form_state['values']['filters']) {
|
|
484 foreach (explode(',', $form_state['values']['filters']) as $string) {
|
|
485 $string = trim($string);
|
|
486 // Minimal validation. ':' must exist and can't be the 1st char..
|
|
487 if (strpos($string, ':')) {
|
|
488 $settings['fq'][] = $string;
|
|
489 }
|
|
490 }
|
|
491 }
|
|
492 $settings['apachesolr_search_custom_enable'] = $form_state['values']['custom_filter_enable'];
|
|
493 $settings['apachesolr_search_search_type'] = $form_state['values']['search_type'];
|
|
494 // Add all advanced settings.
|
|
495 $settings += $form_state['values']['advanced'];
|
|
496
|
|
497 // Set the default search page settings
|
|
498 if (!empty($form_state['values']['make_default']) && isset($form_state['values']['page_id'])) {
|
|
499 variable_set('apachesolr_search_default_search_page', $form_state['values']['page_id']);
|
|
500 }
|
|
501
|
|
502 $search_page = array();
|
|
503 $search_page['page_id'] = $form_state['values']['page_id'];
|
|
504 $search_page['label'] = $form_state['values']['label'];
|
|
505 $search_page['description'] = $form_state['values']['description'];
|
|
506 $search_page['env_id'] = $form_state['values']['env_id'];
|
|
507 $search_page['search_path'] = $form_state['values']['search_path'];
|
|
508 $search_page['page_title'] = $form_state['values']['page_title'];
|
|
509 $search_page['settings'] = $settings;
|
|
510 apachesolr_search_page_save($search_page);
|
|
511
|
|
512 // Saves our values in the database, sets redirect path on success.
|
|
513 drupal_set_message(t('The configuration options have been saved for %page.', array('%page' => $form_state['values']['label'])));
|
|
514 if (isset($form_state['clicked_button']['#redirect'])) {
|
|
515 $form_state['redirect'] = $form_state['clicked_button']['#redirect'];
|
|
516 }
|
|
517 else {
|
|
518 $form_state['redirect'] = current_path();
|
|
519 }
|
|
520 // Regardlessly of the destination parameter we want to go to another page
|
|
521 unset($_GET['destination']);
|
|
522 drupal_static_reset('drupal_get_destination');
|
|
523 drupal_get_destination();
|
|
524 // Menu rebuild needed to pick up search path.
|
|
525 menu_rebuild();
|
|
526 }
|
|
527
|
|
528 /**
|
|
529 * Deletes a single search page configuration.
|
|
530 */
|
|
531 function apachesolr_search_delete_search_page_confirm($form, &$form_state, $search_page) {
|
|
532
|
|
533 // Sets values required for deletion.
|
|
534 $form['page_id'] = array('#type' => 'value', '#value' => $search_page['page_id']);
|
|
535 $form['label'] = array('#type' => 'value', '#value' => $search_page['label']);
|
|
536
|
|
537 if (isset($search_page['export_type']) && $search_page['export_type'] == '3') {
|
|
538 $verb = t('Revert');
|
|
539 }
|
|
540 else {
|
|
541 $verb = t('Delete');
|
|
542 }
|
|
543
|
|
544 // Sets the message, or the title of the page.
|
|
545 $message = t(
|
|
546 'Are you sure you want to !verb the %label search page configuration?',
|
|
547 array('%label' => $form['label']['#value'], '!verb' => strtolower($verb))
|
|
548 );
|
|
549
|
|
550
|
|
551 // Builds caption.
|
|
552 $caption = '<p>';
|
|
553 $caption .= t(
|
|
554 'The %label search page configuration will be deleted.',
|
|
555 array('%label' => $form['label']['#value'])
|
|
556 );
|
|
557 $caption .= '</p>';
|
|
558 $caption .= '<p><strong>' . t('This action cannot be undone.') . '</strong></p>';
|
|
559
|
|
560 // Finalizes and returns the confirmation form.
|
|
561 $return_path = 'admin/config/search/apachesolr/search-pages';
|
|
562 $button_text = $verb;
|
|
563 if (!isset($search_page['settings']['apachesolr_search_not_removable'])) {
|
|
564 return confirm_form($form, filter_xss($message), $return_path, filter_xss($caption), check_plain($button_text));
|
|
565 }
|
|
566 else {
|
|
567 // Maybe this should be solved somehow else
|
|
568 drupal_access_denied();
|
|
569 }
|
|
570 }
|
|
571
|
|
572 /**
|
|
573 * Process content type delete confirm submissions.
|
|
574 */
|
|
575 function apachesolr_search_delete_search_page_confirm_submit($form, &$form_state) {
|
|
576 // Deletes the index configuration settings.
|
|
577 // @todo Invoke a hook that allows backends and indexers to delete their stuff.
|
|
578 db_delete('apachesolr_search_page')
|
|
579 ->condition('page_id', $form_state['values']['page_id'])
|
|
580 ->execute();
|
|
581
|
|
582 // Sets message, logs action.
|
|
583 drupal_set_message(t(
|
|
584 'The %label search page configuration has been deleted.',
|
|
585 array('%label' => $form_state['values']['label'])
|
|
586 ));
|
|
587 watchdog('apachesolr_search', 'Deleted search page configuration "@page_id".', array('@page_id' => $form_state['values']['page_id']), WATCHDOG_NOTICE);
|
|
588
|
|
589 // Rebuilds the menu cache.
|
|
590 menu_rebuild();
|
|
591
|
|
592 // Returns back to search page list page.
|
|
593 $form_state['redirect'] = 'admin/config/search/apachesolr/search-pages';
|
|
594 }
|
|
595
|
|
596 /**
|
|
597 * Clones a single search page configuration
|
|
598 * @param $search_page
|
|
599 * The search page that needs to be cloned
|
|
600 */
|
|
601 function apachesolr_search_clone_search_page_confirm($form, &$form_state, $search_page) {
|
|
602 $form['page_id'] = array(
|
|
603 '#type' => 'value',
|
|
604 '#value' => $search_page['page_id'],
|
|
605 );
|
|
606 return confirm_form(
|
|
607 $form,
|
|
608 t('Are you sure you want to clone search page %name?', array('%name' => $search_page['label'])),
|
|
609 'admin/config/search/apachesolr',
|
|
610 '',
|
|
611 t('Clone'),
|
|
612 t('Cancel')
|
|
613 );
|
|
614 }
|
|
615
|
|
616 /**
|
|
617 * Submits the confirmations of the cloning of a search page
|
|
618 */
|
|
619 function apachesolr_search_clone_search_page_confirm_submit($form, &$form_state) {
|
|
620 if (apachesolr_search_page_clone($form_state['values']['page_id'])) {
|
|
621 drupal_set_message(t('The search page was cloned'));
|
|
622 }
|
|
623 $form_state['redirect'] = 'admin/config/search/apachesolr/search-pages';
|
|
624 }
|
|
625
|
|
626 /**
|
|
627 * Menu callback - the settings form.
|
|
628 */
|
|
629 function apachesolr_search_get_fields($environment = NULL) {
|
|
630 if (empty($environment)) {
|
|
631 $env_id = apachesolr_default_environment();
|
|
632 $environment = apachesolr_environment_load($env_id);
|
|
633 }
|
|
634 $env_id = $environment['env_id'];
|
|
635
|
|
636 // Try to fetch the schema fields.
|
|
637 try {
|
|
638 $solr = apachesolr_get_solr($env_id);
|
|
639 $fields = $solr->getFields();
|
|
640 return $fields;
|
|
641 }
|
|
642 catch (Exception $e) {
|
|
643 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
|
|
644 drupal_set_message(nl2br(check_plain($e->getMessage())), 'warning');
|
|
645 drupal_set_message(t('Cannot get information about the fields in the index.'), 'warning');
|
|
646 }
|
|
647 }
|
|
648
|
|
649 /**
|
|
650 * Menu callback - Bias settings form.
|
|
651 */
|
|
652 function apachesolr_bias_settings_page($environment = NULL) {
|
|
653 if (empty($environment)) {
|
|
654 $env_id = apachesolr_default_environment();
|
|
655 $environment = apachesolr_environment_load($env_id);
|
|
656 }
|
|
657 $env_id = $environment['env_id'];
|
|
658
|
|
659 // Initializes output with information about which environment's setting we are
|
|
660 // editing, as it is otherwise not transparent to the end user.
|
|
661 $output = array(
|
|
662 'apachesolr_environment' => array(
|
|
663 '#theme' => 'apachesolr_settings_title',
|
|
664 '#env_id' => $env_id,
|
|
665 ),
|
|
666 );
|
|
667
|
|
668 // Adds content bias and type boost forms.
|
|
669 $fields = apachesolr_search_get_fields($environment);
|
|
670 $form = array();
|
|
671 $form = drupal_get_form('apachesolr_search_bias_form', $env_id, $fields);
|
|
672 $output['bias_forms'] = $form;
|
|
673 return $output;
|
|
674 }
|
|
675
|
|
676 function apachesolr_search_bias_form($form, &$form_state, $env_id, $fields) {
|
|
677 $form['#env_id'] = $env_id;
|
|
678 $form['bias_tabs'] = array(
|
|
679 '#type' => 'vertical_tabs',
|
|
680 );
|
|
681 $form['actions']['#type'] = 'actions';
|
|
682 $form['actions']['submit'] = array(
|
|
683 '#type' => 'submit',
|
|
684 '#value' => t('Save configuration'),
|
|
685 '#submit' => array('apachesolr_search_bias_form_submit'),
|
|
686 );
|
|
687 $form['actions']['reset'] = array(
|
|
688 '#type' => 'submit',
|
|
689 '#value' => t('Reset to defaults'),
|
|
690 '#submit' => array('apachesolr_search_bias_form_reset'),
|
|
691 );
|
|
692 $form += apachesolr_search_result_bias_form($env_id);
|
|
693 $form += apachesolr_search_type_boost_form($env_id);
|
|
694 $form += apachesolr_search_field_bias_form($fields, $env_id);
|
|
695 return $form;
|
|
696 }
|
|
697
|
|
698 function apachesolr_search_bias_form_submit(&$form, &$form_state) {
|
|
699 // Exclude unnecessary elements.
|
|
700 form_state_values_clean($form_state);
|
|
701 foreach ($form_state['values'] as $key => $value) {
|
|
702 if (is_array($value) && isset($form_state['values']['array_filter'])) {
|
|
703 $value = array_keys(array_filter($value));
|
|
704 }
|
|
705 // There is no need to set default variable values.
|
|
706 if (!isset($form[$key]['#default_value']) || $form[$key]['#default_value'] != $value) {
|
|
707 switch ($key) {
|
|
708 case 'apachesolr_search_sticky_boost' :
|
|
709 case 'apachesolr_search_promote_boost' :
|
|
710 case 'apachesolr_search_date_boost' :
|
|
711 case 'apachesolr_search_comment_boost' :
|
|
712 case 'apachesolr_search_changed_boost' :
|
|
713 case 'apachesolr_search_type_boosts' :
|
|
714 case 'field_bias' :
|
|
715 apachesolr_environment_variable_set($form['#env_id'], $key, $value);
|
|
716 }
|
|
717 }
|
|
718 }
|
|
719 drupal_set_message(t('The configuration options have been saved.'));
|
|
720 }
|
|
721
|
|
722 function apachesolr_search_bias_form_reset($form, &$form_state) {
|
|
723 // Exclude unnecessary elements.
|
|
724 form_state_values_clean($form_state);
|
|
725
|
|
726 foreach ($form_state['values'] as $key => $value) {
|
|
727 apachesolr_environment_variable_del($form['#env_id'], $key);
|
|
728 }
|
|
729 drupal_set_message(t('The configuration options have been reset to their default values.'));
|
|
730 }
|
|
731
|
|
732 /**
|
|
733 * Form builder function to set date, comment, etc biases.
|
|
734 */
|
|
735 function apachesolr_search_result_bias_form($env_id) {
|
|
736
|
|
737 $date_settings = apachesolr_environment_variable_get($env_id, 'apachesolr_search_date_boost', '0:0');
|
|
738 $comment_settings = apachesolr_environment_variable_get($env_id, 'apachesolr_search_comment_boost', '0:0');
|
|
739 $changed_settings = apachesolr_environment_variable_get($env_id, 'apachesolr_search_changed_boost', '0:0');
|
|
740 $sticky_boost = apachesolr_environment_variable_get($env_id, 'apachesolr_search_sticky_boost', '0');
|
|
741 $promote_boost = apachesolr_environment_variable_get($env_id, 'apachesolr_search_promote_boost', '0');
|
|
742
|
|
743 $options = array(
|
|
744 '10:2000.0' => '10',
|
|
745 '8:1000.0' => '9',
|
|
746 '8:700.0' => '8',
|
|
747 '8:500.0' => '7',
|
|
748 '4:300.0' => '6',
|
|
749 '4:200.0' => '5',
|
|
750 '4:150.0' => '4',
|
|
751 '2:150.0' => '3',
|
|
752 '2:100.0' => '2',
|
|
753 '1:100.0' => '1',
|
|
754 '0:0' => t('Ignore'),
|
|
755 );
|
|
756
|
|
757 $weights = drupal_map_assoc(array('21.0', '13.0', '8.0', '5.0', '3.0', '2.0', '1.0', '0.8', '0.5', '0.3', '0.2', '0.1'));
|
|
758 $weights['0'] = t('Ignore');
|
|
759
|
|
760 $form = array();
|
|
761 $form['result_bias'] = array(
|
|
762 '#type' => 'fieldset',
|
|
763 '#title' => t('Result biasing'),
|
|
764 '#collapsible' => TRUE,
|
|
765 '#collapsed' => FALSE,
|
|
766 '#description' => t('Give bias to certain properties when ordering the search results. Any value except <em>Ignore</em> will increase the score of the given type in search results. Choose <em>Ignore</em> to ignore any given property.'),
|
|
767 '#group' => 'bias_tabs',
|
|
768 );
|
|
769 $form['result_bias']['apachesolr_search_sticky_boost'] = array(
|
|
770 '#type' => 'select',
|
|
771 '#options' => $weights,
|
|
772 '#title' => t("Sticky at top of lists"),
|
|
773 '#default_value' => $sticky_boost,
|
|
774 '#description' => t("Select additional bias to give to nodes that are set to be 'Sticky at top of lists'."),
|
|
775 );
|
|
776 $form['result_bias']['apachesolr_search_promote_boost'] = array(
|
|
777 '#type' => 'select',
|
|
778 '#options' => $weights,
|
|
779 '#title' => t("Promoted to home page"),
|
|
780 '#default_value' => $promote_boost,
|
|
781 '#description' => t("Select additional bias to give to nodes that are set to be 'Promoted to home page'."),
|
|
782 );
|
|
783 $form['result_bias']['apachesolr_search_date_boost'] = array(
|
|
784 '#type' => 'select',
|
|
785 '#options' => $options,
|
|
786 '#title' => t("More recently created"),
|
|
787 '#default_value' => $date_settings,
|
|
788 '#description' => t('This setting will change the result scoring so that nodes created more recently may appear before those with higher keyword matching.'),
|
|
789 );
|
|
790 $form['result_bias']['apachesolr_search_comment_boost'] = array(
|
|
791 '#type' => 'select',
|
|
792 '#options' => $options,
|
|
793 '#title' => t("More comments"),
|
|
794 '#default_value' => $comment_settings,
|
|
795 '#description' => t('This setting will change the result scoring so that nodes with more comments may appear before those with higher keyword matching.'),
|
|
796 );
|
|
797 $form['result_bias']['apachesolr_search_changed_boost'] = array(
|
|
798 '#type' => 'select',
|
|
799 '#options' => $options,
|
|
800 '#title' => t("More recent comments"),
|
|
801 '#default_value' => $changed_settings,
|
|
802 '#description' => t('This setting will change the result scoring so that nodes with the most recent comments (or most recent updates to the node itself) may appear before those with higher keyword matching.'),
|
|
803 );
|
|
804 return $form;
|
|
805 }
|
|
806
|
|
807 /**
|
|
808 * Form builder function to set query field weights.
|
|
809 */
|
|
810 function apachesolr_search_field_bias_form($fields, $env_id) {
|
|
811 $form = array();
|
|
812 // get the current weights
|
|
813 $defaults = array(
|
|
814 'content' => '1.0',
|
|
815 'ts_comments' => '0.5',
|
|
816 'tos_content_extra' => '0.1',
|
|
817 'label' => '5.0',
|
|
818 'tos_name' => '3.0',
|
|
819 'taxonomy_names' => '2.0',
|
|
820 'tags_h1' => '5.0',
|
|
821 'tags_h2_h3' => '3.0',
|
|
822 'tags_h4_h5_h6' => '2.0',
|
|
823 'tags_inline' => '1.0',
|
|
824 'tags_a' => '0',
|
|
825 );
|
|
826 $qf = apachesolr_environment_variable_get($env_id, 'field_bias', $defaults);
|
|
827 $weights = drupal_map_assoc(array('21.0', '13.0', '8.0', '5.0', '3.0', '2.0', '1.0', '0.8', '0.5', '0.3', '0.2', '0.1'));
|
|
828 $weights['0'] = t('Omit');
|
|
829 if (!$qf) {
|
|
830 $qf = $defaults;
|
|
831 }
|
|
832 if ($fields) {
|
|
833 $form['field_bias'] = array(
|
|
834 '#type' => 'fieldset',
|
|
835 '#title' => t('Field biases'),
|
|
836 '#collapsible' => TRUE,
|
|
837 '#collapsed' => FALSE,
|
|
838 '#tree' => TRUE,
|
|
839 '#description' => t('Specify here which fields are more important when searching. Give a field a greater numeric value to make it more important. If you omit a field, it will not be searched.'),
|
|
840 '#group' => 'bias_tabs',
|
|
841 );
|
|
842 foreach ($fields as $field_name => $field) {
|
|
843 // Only indexed feids are searchable.
|
|
844 if ($field->schema{0} == 'I') {
|
|
845 // By default we only show text fields. Use hook_form_alter to change.
|
|
846 // We use filter_xss to make sure links are allowed
|
|
847 $form['field_bias'][$field_name] = array(
|
|
848 '#access' => ($field->type == 'text' || $field->type == 'text_und'),
|
|
849 '#type' => 'select',
|
|
850 '#options' => $weights,
|
|
851 '#title' => filter_xss(apachesolr_field_name_map($field_name)),
|
|
852 '#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : '0',
|
|
853 );
|
|
854 }
|
|
855 }
|
|
856
|
|
857 // Make sure all the default fields are included, even if they have
|
|
858 // no indexed content.
|
|
859 foreach ($defaults as $field_name => $weight) {
|
|
860 $form['field_bias'][$field_name] = array(
|
|
861 '#type' => 'select',
|
|
862 '#options' => $weights,
|
|
863 '#title' => check_plain(apachesolr_field_name_map($field_name)),
|
|
864 '#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : $defaults[$field_name],
|
|
865 );
|
|
866 }
|
|
867
|
|
868 ksort($form['field_bias']);
|
|
869 }
|
|
870 return $form;
|
|
871 }
|
|
872
|
|
873 /**
|
|
874 * Form builder function to set query type weights.
|
|
875 */
|
|
876 function apachesolr_search_type_boost_form($env_id) {
|
|
877
|
|
878 $form['type_boost'] = array(
|
|
879 '#type' => 'fieldset',
|
|
880 '#title' => t('Type biasing'),
|
|
881 '#collapsible' => TRUE,
|
|
882 '#collapsed' => FALSE,
|
|
883 '#group' => 'bias_tabs',
|
|
884 );
|
|
885 $form['type_boost']['apachesolr_search_type_boosts'] = array(
|
|
886 '#type' => 'item',
|
|
887 '#description' => t("Specify here which node types should get a higher relevancy score in searches. Any value except <em>Ignore</em> will increase the score of the given type in search results."),
|
|
888 '#tree' => TRUE,
|
|
889 );
|
|
890
|
|
891 $weights = drupal_map_assoc(array('21.0', '13.0', '8.0', '5.0', '3.0', '2.0', '1.0', '0.8', '0.5', '0.3', '0.2', '0.1'));
|
|
892 $weights['0'] = t('Ignore');
|
|
893
|
|
894 // Get the current boost values.
|
|
895 $type_boosts = apachesolr_environment_variable_get($env_id, 'apachesolr_search_type_boosts', array());
|
|
896 $names = array();
|
|
897 foreach (entity_get_info() as $entity_type => $entity_info) {
|
|
898 if (!empty($entity_info['apachesolr']['indexable'])) {
|
|
899 foreach ($entity_info['bundles'] as $key => $info) {
|
|
900 $names[$key] = $info['label'];
|
|
901 }
|
|
902 }
|
|
903 }
|
|
904 asort($names);
|
|
905
|
|
906 foreach ($names as $type => $name) {
|
|
907 $form['type_boost']['apachesolr_search_type_boosts'][$type] = array(
|
|
908 '#type' => 'select',
|
|
909 '#title' => t('%type type content bias', array('%type' => $name)),
|
|
910 '#options' => $weights,
|
|
911 '#default_value' => isset($type_boosts[$type]) ? $type_boosts[$type] : 0,
|
|
912 );
|
|
913 }
|
|
914
|
|
915 return $form;
|
|
916 }
|
|
917
|
|
918 /**
|
|
919 * MoreLikeThis administration and utility functions.
|
|
920 */
|
|
921 function apachesolr_search_mlt_add_block_form() {
|
|
922 $form = apachesolr_search_mlt_block_form();
|
|
923 $form['submit'] = array(
|
|
924 '#type' => 'submit',
|
|
925 '#value' => t('Save'),
|
|
926 '#weight' => '5',
|
|
927 );
|
|
928 return $form;
|
|
929 }
|
|
930
|
|
931 function apachesolr_search_mlt_add_block_form_submit($form, &$form_state) {
|
|
932 apachesolr_search_mlt_save_block($form_state['values']);
|
|
933 $block_message = t('New More like this block created. <a href="!configure">Configure</a> this block in the Block administration', array('!configure' => url('admin/structure/block')));
|
|
934 drupal_set_message($block_message);
|
|
935 $form_state['redirect'] = 'admin/config/search/apachesolr/search-pages';
|
|
936 }
|
|
937
|
|
938 /**
|
|
939 * Merge supplied settings with the standard defaults..
|
|
940 */
|
|
941 function apachesolr_search_mlt_block_defaults($block = array()) {
|
|
942 return $block + array(
|
|
943 'name' => '',
|
|
944 'num_results' => '5',
|
|
945 'mlt_fl' => array(
|
|
946 'label' => 'label',
|
|
947 'taxonomy_names' => 'taxonomy_names',
|
|
948 ),
|
|
949 'mlt_env_id' => 'solr',
|
|
950 'mlt_mintf' => '1',
|
|
951 'mlt_mindf' => '1',
|
|
952 'mlt_minwl' => '3',
|
|
953 'mlt_maxwl' => '15',
|
|
954 'mlt_maxqt' => '20',
|
|
955 'mlt_type_filters' => array(),
|
|
956 'mlt_custom_filters' => '',
|
|
957 );
|
|
958 }
|
|
959
|
|
960 /**
|
|
961 * Constructs a list of field names used on the settings form.
|
|
962 *
|
|
963 * @return array An array containing a the fields in the solr instance.
|
|
964 */
|
|
965 function apachesolr_search_mlt_get_fields() {
|
|
966 $rows = array();
|
|
967
|
|
968 try {
|
|
969 $solr = apachesolr_get_solr();
|
|
970 $fields = $solr->getFields();
|
|
971 foreach ($fields as $field_name => $field) {
|
|
972 if ($field->schema{4} == 'V') {
|
|
973 $rows[$field_name] = apachesolr_field_name_map($field_name);
|
|
974 }
|
|
975 }
|
|
976 ksort($rows);
|
|
977 }
|
|
978 catch (Exception $e) {
|
|
979 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
|
|
980 }
|
|
981
|
|
982 return $rows;
|
|
983 }
|
|
984
|
|
985 /**
|
|
986 * A helper function to save MLT block data.
|
|
987 *
|
|
988 * If passed a block delta, the function will update block settings. If it is
|
|
989 * not passed a block delta, the function will create a new block.
|
|
990 *
|
|
991 * @param array $block_settings An array containing the settings required to form
|
|
992 * a moreLikeThis request.
|
|
993 *
|
|
994 * @param int $delta The id of the block you wish to update.
|
|
995 */
|
|
996 function apachesolr_search_mlt_save_block($block_settings = array(), $delta = NULL) {
|
|
997 $blocks = variable_get('apachesolr_search_mlt_blocks', array());
|
|
998 if (is_null($delta)) {
|
|
999 $count = 0;
|
|
1000 ksort($blocks);
|
|
1001 // Construct a new array key.
|
|
1002 if (end($blocks)) {
|
|
1003 list(, $count) = explode('-', key($blocks));
|
|
1004 }
|
|
1005 $delta = sprintf('mlt-%03d', 1 + $count);
|
|
1006 }
|
|
1007 $defaults = apachesolr_search_mlt_block_defaults();
|
|
1008 // Remove stray form values.
|
|
1009 $blocks[$delta] = array_intersect_key($block_settings, $defaults) + $defaults;
|
|
1010 // Eliminate non-selected fields.
|
|
1011 $blocks[$delta]['mlt_fl'] = array_filter($blocks[$delta]['mlt_fl']);
|
|
1012 $blocks[$delta]['delta'] = $delta;
|
|
1013 $blocks[$delta]['mlt_type_filters'] = array_filter($blocks[$delta]['mlt_type_filters']);
|
|
1014 $blocks[$delta]['mlt_custom_filters'] = trim($blocks[$delta]['mlt_custom_filters']);
|
|
1015 variable_set('apachesolr_search_mlt_blocks', $blocks);
|
|
1016 }
|
|
1017
|
|
1018 function apachesolr_search_mlt_delete_block_form($form, &$form_state, $block) {
|
|
1019 if ($block) {
|
|
1020 // Backwards compatibility for the block deltas
|
|
1021 if (isset($block['delta'])) {
|
|
1022 $delta = $block['delta'];
|
|
1023 }
|
|
1024 else {
|
|
1025 $delta = arg(6);
|
|
1026 }
|
|
1027 // Add our delta to the delete form
|
|
1028 $form['delta'] = array(
|
|
1029 '#type' => 'value',
|
|
1030 '#value' => $delta,
|
|
1031 );
|
|
1032 $question = t('Are you sure you want to delete the "More Like this" block %name?', array('%name' => $block['name']));
|
|
1033 $path = 'admin/structure/block';
|
|
1034 $description = t('The block will be deleted. This action cannot be undone.');
|
|
1035 $yes = t('Delete');
|
|
1036 $no = t('Cancel');
|
|
1037 return confirm_form($form, filter_xss($question), $path, $description, $yes, $no);
|
|
1038 }
|
|
1039 }
|
|
1040
|
|
1041 function apachesolr_search_mlt_delete_block_form_submit($form, &$form_state) {
|
|
1042 $blocks = apachesolr_search_load_all_mlt_blocks();
|
|
1043
|
|
1044 unset($blocks[$form_state['values']['delta']]);
|
|
1045 variable_set('apachesolr_search_mlt_blocks', $blocks);
|
|
1046 drupal_set_message(t('The block has been deleted.'));
|
|
1047 $form_state['redirect'] = 'admin/config/search/apachesolr/search-pages';
|
|
1048 }
|
|
1049
|
|
1050 /**
|
|
1051 * Form to edit moreLikeThis block settings.
|
|
1052 *
|
|
1053 * @param int $delta If editing, the id of the block to edit.
|
|
1054 *
|
|
1055 * @return array The form used for editing.
|
|
1056 * @todo Add term boost settings.
|
|
1057 * @todo Enable the user to specify a query, rather then forcing suggestions
|
|
1058 * based on the node id.
|
|
1059 */
|
|
1060 function apachesolr_search_mlt_block_form($block_id = NULL) {
|
|
1061 if (!empty($block_id)) {
|
|
1062 $block = apachesolr_search_mlt_block_load($block_id);
|
|
1063 if (!$block) {
|
|
1064 return array();
|
|
1065 }
|
|
1066 }
|
|
1067 else {
|
|
1068 $block = apachesolr_search_mlt_block_defaults();
|
|
1069 }
|
|
1070
|
|
1071 $form['delta'] = array(
|
|
1072 '#type' => 'value',
|
|
1073 '#default_value' => isset($block['delta']) ? $block['delta'] : '',
|
|
1074 '#weight' => '-2',
|
|
1075 );
|
|
1076
|
|
1077 $form['name'] = array(
|
|
1078 '#type' => 'textfield',
|
|
1079 '#title' => t('Block name'),
|
|
1080 '#description' => t('The block name displayed to site users.'),
|
|
1081 '#required' => TRUE,
|
|
1082 '#default_value' => isset($block['name']) ? $block['name'] : '',
|
|
1083 '#weight' => '-2',
|
|
1084 );
|
|
1085
|
|
1086 $environments = apachesolr_load_all_environments();
|
|
1087 $options = array('' => t('<Disabled>'));
|
|
1088 foreach ($environments as $id => $environment) {
|
|
1089 $options[$id] = $environment['name'];
|
|
1090 }
|
|
1091 $form['mlt_env_id'] = array(
|
|
1092 '#title' => t('Search environment'),
|
|
1093 '#type' => 'select',
|
|
1094 '#options' => $options,
|
|
1095 '#default_value' => isset($block['mlt_env_id']) ? $block['mlt_env_id'] : apachesolr_default_environment(),
|
|
1096 );
|
|
1097
|
|
1098 $form['num_results'] = array(
|
|
1099 '#type' => 'select',
|
|
1100 '#title' => t('Maximum number of related items to display'),
|
|
1101 '#default_value' => isset($block['num_results']) ? $block['num_results'] : '',
|
|
1102 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)),
|
|
1103 '#weight' => -1,
|
|
1104
|
|
1105 );
|
|
1106 $form['mlt_fl'] = array(
|
|
1107 '#type' => 'checkboxes',
|
|
1108 '#title' => t('Fields for finding related content'),
|
|
1109 '#description' => t('Choose the fields to be used in calculating similarity. The default combination of %taxonomy_names and %title will provide relevant results for typical sites.', array("%taxonomy_names" => apachesolr_field_name_map("taxonomy_names"), "%title" => apachesolr_field_name_map("label"))),
|
|
1110 '#options' => apachesolr_search_mlt_get_fields(),
|
|
1111 '#required' => TRUE,
|
|
1112 '#default_value' => isset($block['mlt_fl']) ? $block['mlt_fl'] : '',
|
|
1113 );
|
|
1114 $form['advanced'] = array(
|
|
1115 '#type' => 'fieldset',
|
|
1116 '#title' => t('Advanced configuration'),
|
|
1117 '#weight' => '1',
|
|
1118 '#collapsible' => TRUE,
|
|
1119 '#collapsed' => TRUE,
|
|
1120 );
|
|
1121 $options = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7));
|
|
1122 $form['advanced']['mlt_mintf'] = array(
|
|
1123 '#type' => 'select',
|
|
1124 '#title' => t('Minimum term frequency'),
|
|
1125 '#description' => t('A word must appear this many times in any given document before the document is considered relevant for comparison.'),
|
|
1126 '#default_value' => isset($block['mlt_mintf']) ? $block['mlt_mintf'] : '',
|
|
1127 '#options' => $options,
|
|
1128 );
|
|
1129 $form['advanced']['mlt_mindf'] = array(
|
|
1130 '#type' => 'select',
|
|
1131 '#title' => t('Minimum document frequency'),
|
|
1132 '#description' => t('A word must occur in at least this many documents before it will be used for similarity comparison.'),
|
|
1133 '#default_value' => isset($block['mlt_mindf']) ? $block['mlt_mindf'] : '',
|
|
1134 '#options' => $options,
|
|
1135 );
|
|
1136 $form['advanced']['mlt_minwl'] = array(
|
|
1137 '#type' => 'select',
|
|
1138 '#title' => t('Minimum word length'),
|
|
1139 '#description' => 'You can use this to eliminate short words such as "the" and "it" from similarity comparisons. Words must be at least this number of characters or they will be ignored.',
|
|
1140 '#default_value' => isset($block['mlt_minwl']) ? $block['mlt_minwl'] : '',
|
|
1141 '#options' => $options,
|
|
1142 );
|
|
1143 $form['advanced']['mlt_maxwl'] = array(
|
|
1144 '#type' => 'select',
|
|
1145 '#title' => t('Maximum word length'),
|
|
1146 '#description' => t('You can use this to eliminate very long words from similarity comparisons. Words of more than this number of characters will be ignored.'),
|
|
1147 '#default_value' => isset($block['mlt_maxwl']) ? $block['mlt_maxwl'] : '',
|
|
1148 '#options' => drupal_map_assoc(array(8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
|
|
1149 );
|
|
1150 $form['advanced']['mlt_maxqt'] = array(
|
|
1151 '#type' => 'select',
|
|
1152 '#title' => t('Maximum number of query terms'),
|
|
1153 '#description' => t('The maximum number of query terms that will be included in any query. Lower numbers will result in fewer recommendations but will get results faster. If a content recommendation is not returning any recommendations, you can either check more "Comparison fields" checkboxes or increase the maximum number of query terms here.'),
|
|
1154 '#options' => drupal_map_assoc(array(3, 5, 7, 10, 12, 15, 20, 25, 30, 35, 40)),
|
|
1155 '#default_value' => isset($block['mlt_maxqt']) ? $block['mlt_maxqt'] : '',
|
|
1156 );
|
|
1157
|
|
1158 $form['restrictions'] = array(
|
|
1159 '#type' => 'fieldset',
|
|
1160 '#title' => t('Filters'),
|
|
1161 '#weight' => '1',
|
|
1162 '#collapsible' => TRUE,
|
|
1163 '#collapsed' => TRUE,
|
|
1164 );
|
|
1165
|
|
1166 $type_options = array();
|
|
1167 foreach (node_type_get_types() as $key => $type) {
|
|
1168 $type_options[$key] = $type->name;
|
|
1169 }
|
|
1170
|
|
1171 $form['restrictions']['mlt_type_filters'] = array(
|
|
1172 '#type' => 'checkboxes',
|
|
1173 '#title' => t('Content Types'),
|
|
1174 '#default_value' => is_array($block['mlt_type_filters']) ? $block['mlt_type_filters'] : array(),
|
|
1175 '#options' => $type_options,
|
|
1176 '#description' => t('Select the content types that similarity suggestions should be restricted to. Multiple types are joined with an OR query, so selecting more types results in more recommendations. If none are selected, no filter will be applied.'),
|
|
1177 '#weight' => '-2',
|
|
1178 );
|
|
1179
|
|
1180 $form['restrictions']['mlt_custom_filters'] = array(
|
|
1181 '#type' => 'textfield',
|
|
1182 '#title' => t('Additional Query'),
|
|
1183 '#description' => t("A query, in Lucene syntax, which will further filter the similarity suggestions. For example, 'label:strategy' will filter related content further to only those with strategy in the title. Here are some more examples:") .
|
|
1184 '<ul>
|
|
1185 <li>ss_language:fr</li>
|
|
1186 <li>tid:(5 OR 7)</li>
|
|
1187 <li>ds_created:[2009-05-01T23:59:59Z TO 2009-07-28T12:30:00Z]</li>
|
|
1188 <li>-is_uid:0, -is_uid:1</li>
|
|
1189 </ul>',
|
|
1190 '#required' => FALSE,
|
|
1191 '#default_value' => isset($block['mlt_custom_filters']) ? $block['mlt_custom_filters'] : '',
|
|
1192 '#weight' => '-1',
|
|
1193 );
|
|
1194
|
|
1195 return $form;
|
|
1196 }
|