- 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]
Comments
add_field changed to add_filter ?
I believe there's been an api change with the latest release.
Basically add_field() member function changed to add_filter()
http://drupalwork.interestsphere.com/
http://drupalmashup.interestsphere.com/
Updated
The handbook page has been updated.
need hook_search?
So does "Any module performing a search" imply that your module is implementing hook_search?
hook_search is to define a
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')
query interface documentation?
It would be really, really nice to have a link to any documentation on the interface to the $query object referred to here (Drupal_Solr_Query_Interface). I spent an afternoon searching and wound up reading the module source code.
Edited to add another 'really'. Still searching days later. What's in the query? What's in params? Why are my added filters lost when I set aliases? Is it a bug or am I using it wrong? Heck if I know. It has to be written down somewhere.
I agree...
I have been searching for implementation on doing a simple search outside of the core just for a news area, so far I can return ALL results but the keys aren't working and nowhere can I find proper documentation on this.
Could someone shed some light on what I am doing wrong?
King regards,
Hugh Wood
Mastersallen.co.uk
Integer CCK integration
After developing some code for a website that we were building that required the integration of CCK types that were of type integer I thought I would post the following code to help others out.
CCK fields alter (CCK strings deal with these types out of the box but not for integers tragically)
Next function renders the checklist block
Finally the display callback (which is pretty basic)
custom search and facete block
I've moved from faceted_search to apachesolr and missed the faceted_search navigation blocks. Apachesolr only shows it's blocks on the search pages (search/apachesolr). This is a quick hack to perform a custom search and show the corresponding taxonomy facete block. (apachesolr 6.x-2.x-dev)
Here's the live page using this code: http://4soldo.ru/store (in russian)
The same result can be acheived with apachesolr_views, but it's for views 3 only.
Hope it helps someone.
I am dealing with the same
I am dealing with the same issue as MA-Hugh...