Exposed Hooks (D6) for developers

Last modified: September 25, 2009 - 19:43
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_field("uid", 1);         
}

hook_apachesolr_cck_fields_alter(&$mappings)

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

$mappings['text'] = array(
  'optionwidgets_select' => array('callback' => '', 'index_type' => 'string'),
  'optionwidgets_buttons' => array('callback' => '', 'index_type' => 'string')
);

In your _alter hook implementation you can add additional fild types such as:
$mappings['number_integer']['number'] = array('callback' => '', 'index_type' => 'integer');

You can allso 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');

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 is somewhat outdated, but may still be helpful: Using hook_apachesolr_cck_field_mappings()

add_field changed to add_filter ?

poka_dan - April 27, 2009 - 15:19

I believe there's been an api change with the latest release.
Basically add_field() member function changed to add_filter()

need hook_search?

emackn - August 12, 2009 - 19:35

So does "Any module performing a search" imply that your module is implementing hook_search?

hook_search is to define a

aufumy - September 25, 2009 - 15:31

hook_search is to define a new type of search, so it would not mean that.

I believe it meant if your module is calling apachesolr_search_execute($keys, $filters, $solrsort, $base_path = '', $page = 0, $caller = 'apachesolr_search')

 
 

Drupal is a registered trademark of Dries Buytaert.