function apachesolr_search_field_bias_form in Apache Solr Search 6.3
Same name and namespace in other branches
- 8 apachesolr_search.admin.inc \apachesolr_search_field_bias_form()
- 7 apachesolr_search.admin.inc \apachesolr_search_field_bias_form()
Form builder function to set query field weights.
1 call to apachesolr_search_field_bias_form()
File
- ./
apachesolr_search.admin.inc, line 871 - Administrative settings for searching.
Code
function apachesolr_search_field_bias_form($fields, $env_id) {
$form = array();
// get the current weights
$defaults = array(
'content' => '1.0',
'ts_comments' => '0.5',
'tos_content_extra' => '0.1',
'label' => '5.0',
'tos_name' => '3.0',
'taxonomy_names' => '2.0',
'tags_h1' => '5.0',
'tags_h2_h3' => '3.0',
'tags_h4_h5_h6' => '2.0',
'tags_inline' => '1.0',
'tags_a' => '0',
);
$qf = apachesolr_environment_variable_get($env_id, 'field_bias', $defaults);
$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',
));
$weights['0'] = t('Omit');
if (!$qf) {
$qf = $defaults;
}
if ($fields) {
$form['field_bias'] = array(
'#type' => 'fieldset',
'#title' => t('Field biases'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#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.'),
'#group' => 'bias_tabs',
);
foreach ($fields as $field_name => $field) {
// Only indexed feids are searchable.
if (strpos($field->schema, 'I') !== FALSE) {
// By default we only show text fields. Use hook_form_alter to change.
// We use filter_xss to make sure links are allowed
$form['field_bias'][$field_name] = array(
'#access' => $field->type == 'text' || $field->type == 'text_und',
'#type' => 'select',
'#options' => $weights,
'#title' => filter_xss(apachesolr_field_name_map($field_name)),
'#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : '0',
);
}
}
// Make sure all the default fields are included, even if they have
// no indexed content.
foreach ($defaults as $field_name => $weight) {
$form['field_bias'][$field_name] = array(
'#type' => 'select',
'#options' => $weights,
'#title' => check_plain(apachesolr_field_name_map($field_name)),
'#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : $defaults[$field_name],
);
}
ksort($form['field_bias']);
}
return $form;
}