function apachesolr_text_apachesolr_modify_query in Apache Solr Search 6.2
Modify searches to include CCK text fields.
File
- contrib/
apachesolr_text/ apachesolr_text.module, line 55
Code
function apachesolr_text_apachesolr_modify_query(&$query, &$params, $caller) {
global $user;
module_load_include('inc', 'content', 'includes/content.crud');
$cck_field_instances = content_field_instance_read();
$cck_fields = apachesolr_cck_fields();
$keys = htmlspecialchars($query
->get_query_basic(), ENT_NOQUOTES, 'UTF-8');
foreach ($cck_field_instances as $field) {
$allowed = content_permissions_field_access('view', $field, $user);
if ($allowed) {
$field_name = 'ts_cck_' . $field['field_name'];
if (strpos($params['fl'], $field_name) === FALSE) {
$params['fl'] .= ',' . $field_name;
$params['qf'][] = "{$field_name}^1.0";
$params['hl.fl'] .= ",{$field_name}";
// The comma separated strings are problematic as they don't work if they have a comma at the front.
$params['hl.fl'] = implode(',', array_filter(explode(',', $params['hl.fl'])));
}
}
}
// If we set qf explicitly, it wipes out the sensible defaults from solrconfig.xml.
// Thus we put them back in here, else nothing works at all.
if (isset($params['qf'])) {
foreach (explode(' ', 'body^40.0 title^5.0 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') as $qf) {
$params['qf'][] = $qf;
}
}
// Likewise, setting hl.fl wipes solrconfig.xml settings.
if (isset($params['hl.fl']) && strpos($params['hl.fl'], 'body') === FALSE) {
$params['hl.fl'] .= ',body';
}
}