Skip to main content

Expanding indexed content with Search API Data Alterations

Chris Johnson | VP, Engineering

September 21, 2011


The Search API module for Drupal 7 offers a lot of cool features for configuring and creating search pages. For developers of complex applications, it also offers some great functionality through its data alteration capability that can be easy to overlook. The search_api_attachments module is a good example of how to use data alterations to expand the data available for indexing. The key hook is hook_search_api_alter_callback_info() and it is documented in search_api.api.php. This hook lets you declare a data alteration that site administrators can enable when configuring an index. After installing a module that offers data alterations they will show on the workflow section of the index configuration where they will need to be enabled. Once enabled, each data item the alteration provides will show on the fields section of the index configuration where the desired items can be selected for inclusion in the index. In the case of search_api_attachments each file field for the entity being indexed will have an option for being included in the index. Writing your own data alteration is relatively straightforward. Simply create a class implementing the SearchApiAlterCallbackInterface and use the search_api_alter_callback_info hook to tell search_api about it. The interface is defined in the includes/callback.inc file of the search_api module and each required method is well commented there. If you haven't had a chance to check out the search_api module give it a shot. There is a good walkthrough in the Search API section of the Site Building Guide and some pointers to other techniques for adding data for searching on the Search API project page


Recommended Next
Development
A Developer's Guide For Contributing To Drupal
Black pixels on a grey background
Development
3 Steps to a Smooth Salesforce Integration
Black pixels on a grey background
Development
Drupal 8 End of Life: What You Need To Know
Woman working on a laptop
Jump back to top