function rich_snippets_apachesolr_query_alter in Rich Snippets 7
Implements hook_apachesolr_query_alter().
Include all fields that have associated schema.
File
- ./
rich_snippets.apachesolr.inc, line 114 - Apache Solr Search Integration hook implementations and helper functions.
Code
function rich_snippets_apachesolr_query_alter($query) {
$solr_fields = array();
// Add highlighting to the title.
$query
->addParam('hl.fl', 'label');
// Load the Apache Solr Search Integration API functions if they don't exist.
if (!function_exists('apachesolr_get_field_mappings')) {
module_load_include('inc', 'rich_snippets', 'rich_snippets.legacy_apachesolr_get_field_mappings');
}
if (!function_exists('apachesolr_get_index_key_map')) {
module_load_include('inc', 'rich_snippets', 'rich_snippets.legacy_apachesolr_get_index_key_map');
}
// Load the environment associated with this query.
$env_id = $query
->solr('getId');
$enviromnent = apachesolr_environment_load($env_id);
// For all bundles indexed by this environment, gather a list of Solr fields
// that will need to be returned by the Solr server so we can append them to
// the rich snippets.
foreach ($enviromnent['index_bundles'] as $entity_type => $bundles) {
$key_mappings = apachesolr_get_index_key_map($entity_type);
foreach ($bundles as $bundle) {
$rdf_mappings = rich_snippets_get_rdf_schema_mappings($entity_type, $bundle);
foreach ($rdf_mappings as $schema => $fields) {
foreach ($fields as $field) {
if (0 === strpos($field, 'field_') && isset($key_mappings[$field])) {
// Map the fiel to the corresponsding field in Solr.
$solr_fields[$field] = array(
$key_mappings[$field],
);
// Assume that images map to an image field, so add the info field.
if ('image' == $schema) {
$solr_fields[$field][] = rich_snippets_get_apachesolr_image_info_field($key_mappings[$field]);
}
}
}
}
}
}
// Add each field to the list of returned fields.
foreach ($solr_fields as $field_names) {
foreach ($field_names as $field_name) {
$query
->addParam('fl', $field_name);
}
}
// Add the field storing the schema mappings.
$query
->addParam('fl', 'zm_rdf_schema_mappings');
}