Expanding indexed content with Search API Data Alterations

Posted Sep 21, 2011 // 0 comments
Chris:

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

About Chris

As a Senior Web Developer with us, Chris Johnson specializes in high-performance database-backed systems; particularly those that are highly configurable and self-documenting. (Plus, he amicably explains what all that means to inquiring ...

more >

Read Chris's Blog

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <strong> <code> <p> <img> <ul> <ol> <li> <h2> <h3> <h4> <b> <u> <i>
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.