Exposed Solr Hooks (6.x-1.x) for developers

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

hook_apachesolr_modify_query(&$query, &$params, $caller);

Any module performing a search should call apachesolr_modify_query($query, $params, 'modulename'). That function then invokes this hook. It allows modules to modify the query object and params array. $caller indicates which module is invoking the hook.

Example:

function my_module_apachesolr_modify_query(&$query, &$params, $caller) {
   // I only want to see articles by the admin!
   $query->add_filter("uid", 1);          
}

Also we can add "query" filters .An example is :

$query->add_filter("_query_", '{!geofilt sfield=location pt=36.7344685,-6.43353209 d=10}');
hook_apachesolr_cck_fields_alter(&$mappings)

Add or alter index mappings for CCK types. The default mappings array handles just
text and integer fields with option widgets:

$mappings['text'] = array(
  'optionwidgets_select' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE),
  'optionwidgets_buttons' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE),
  'optionwidgets_onoff' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE),
);
$mappings['number_integer'] = array(
  'optionwidgets_select' => array('callback' => '', 'index_type' => 'sint', 'facets' => TRUE),
  'optionwidgets_buttons' => array('callback' => '', 'index_type' => 'sint', 'facets' => TRUE),
  'optionwidgets_onoff' => array('callback' => '', 'index_type' => 'sint', 'facets' => TRUE),
);

This array has the form $mappings[$field_data_type][$field_widget_type]. In your _alter hook implementation you can add additional field types such as:

$mappings['number_integer']['number'] = array('callback' => '', 'index_type' => 'integer');

You can also add a mapping for a specific field. This will take precedence over any
mapping for a general field type. A field-specific mapping would look like:

$mappings['per-field']['field_model_name'] = array('callback' => '', 'index_type' => 'string');

or

$mappings['per-field']['field_model_price'] = array('callback' => '', 'index_type' => 'float');

If a callback is provided, it should have the signature my_callback($node, $cck_field_name), This function will be called before hook_apachesolr_update_index and should return a list of the value(s) which will be indexed in that field.

hook_apachesolr_node_exclude($node)
This is invoked by apachesolr.module for each node to be added to the index - if any module returns TRUE, the node is skipped for indexing. For example, this is used by apachesolr_search module to exclude certain node types from the index.
hook_apachesolr_update_index(&$document, $node)
Allows a module to change the contents of the $document object before it is sent to the Solr Server. To add a new field to the document, you should generally use one of the pre-defined dynamic fields. Follow the naming conventions for the type of data being added based on the schema.xml file.
hook_apachesolr_search_result_alter(&$doc)
The is invoked by apachesolr_search.module for each document returned in a search - new in 6.x-dev as a replacement for the call to hook_nodeapi().
hook_apachesolr_process_results(&$results)
Invoked by apachesolr_search.module on the results array, after hook_apachesolr_search_result_alter above.
hook_apachesolr_sort_links_alter(&$sort_links)
Called by the sort link block code. Allows other modules to modify, add or remove sorts.

This post may be helpful: Using hook_apachesolr_cck_field_mappings() [Updated on April 20, 2010]

Help improve this page

Page status: Not set

You can: