How to add metatag module data to the Search API indexes I am in the process of building a new site that will have some content in the form of videos and PDFs. To make those more searchable I added the metatag module. We are also using the Search API to hook into Solr and do our search operations.

I have found the hooks I need to insert, update, and delete metatag info from the metatag fields. That part is fairly straight forward.

However, I am stuck on the part where I tell the Search API about the fields so that they can be indexed. I think I will be able to figure out how to push the data to the index with the hooks. I just don't know how to tell the Search API that the fields are there and that they contain strings.

I was looking, originally, at the hook_search_api_item_type_info(). However, after reading the description in the API documentation (in the code) I realize that it is only for new entity types. These metatag fields are mainly attached to nodes. And the documentation specifically says that it should not be used for existing entity types (i.e. nodes) because this hook simply tells about the data controller classes.

Should I use hook_search_api_alter_callback_info() to do this? That seems like a good candidate, but I am just not quite following how this works in the SearchAPI.

How do I tell the Search API that the metatag fields exist and I want to be able to index them?

This is in Drupal 7.
I do it like this:
First 

  function HOOK_search_api_alter_callback_info() {
  $callbacks['search_api_alter_add_keywords_field'] = array(
    'name' =&gt; t('Keywords field from metatag module'),
    'description' =&gt; t("Adds Keyword field from metatag module to indexed data."),
    'class' =&gt; 'SearchApiAddKeywordField',
  );
  return $callbacks;
}


Second 

class SearchApiAddKeywordField extends SearchApiAbstractAlterCallback {      
  public function alterItems(array &amp;$items) {
  foreach ($items as $id =&gt; &amp;$item) {
      if (!isset($item-&gt;metatags[$item-&gt;language]['keywords']['value'])) {

        $item-&gt;search_api_keyword = NULL;
        continue;
      }
      $item-&gt;search_api_keyword = strtolower ($item-&gt;metatags[$item-&gt;language]['keywords']['value']);
    }
  }

  public function propertyInfo() {
    return array(
      'search_api_keyword' =&gt; array(
        'label' =&gt; t('Keyword field'),
        'description' =&gt; t('Add keyword field to index.'),
        'type' =&gt; 'text',
      ),
    );
  }

}



After Clear cache go to you index filters and check: Keywords field from metatag module
If Boost settings need to be changed (to give more importance to the field) do it now.
Index Again
Go to the search results view - the view you created to list indexed content.
Assuming that you have fulltext search filter in "Searched fields" select the new "field" Keyword field
Test the things out.