I added "foobar" as a metatag keyword to a node, re-indexed the search index and searched with the core search function for "foobar". I got 0 results.

It would be great if metatags would index all (or selectable) meta tags for the core search function.

Comments

marcoka’s picture

Status: Active » Closed (works as designed)

as far as i know core search indexes content/title field and so on. but not metatags.

no2e’s picture

So is this not a legitimate feature request for Meta tags?

A (untested) work-around is:

  1. add a field for each meta name type
  2. add the tokens for these fields as a pattern in Meta tags
  3. hide the fields in teasers/full, but "display" them for index
marcoka’s picture

meta tag quick uses fields. meta tags doesnt add any fields to your content type. so i think that means restructuring the basical architectural concept.
in my opinion this is a very very unique feature you are requesting.

you use tokens with metatags right? why not just add own fields to the content type and add tokens there. then you can index these fields.

DamienMcKenna’s picture

Status: Closed (works as designed) » Active
mstrelan’s picture

Issue summary: View changes

I think this is a very valid feature request for Metatag, or a perfect candidate for another contrib module. Adding extra fields and hiding them is a PITA, especially since the available metatag fields seems to be constantly evolving. These steps should be a good starting point.

  1. Implement hook_entity_view() to add the Metatags to the entity when rendered using the search index view mode.
  2. Optionally implement hook_field_extra_fields() to expose a metatags field to the search index view mode.
  3. Develop an admin interface to include/exclude certain tags per entity/bundle. Possibly via formatter settings of the extra field

Alternatively, if you only want to implement this for nodes, skip the first 2 steps and implement hook_node_update_index().

DamienMcKenna’s picture

This would need hook_node_update_index() to be implemented.

mstrelan’s picture

Not necessarily. If the metatags are rendered by node_view() with the search_index view mode then they will be indexed automatically. See https://api.drupal.org/api/drupal/modules%21node%21node.module/function/...

DamienMcKenna’s picture

@mstrelan: That's true. I think, however, it'd be cleaner to implement hook_node_update_index than to get a bit hacky with view modes in metatag_entity_view.

mstrelan’s picture

I'm not fussed either way, and for the project I'm working on I've done a simple implementation of hook_node_update_index().

I would disagree that the view mode approach is more hacky. For one, it automatically would support other entity types, such as file entities (see http://www.drupalcontrib.org/api/drupal/contributions%21file_entity%21fi...). Secondly, that's the exact way fields are included in the index. And finally, this is the same way other contrib modules, such as Commerce, would add their data to the search index.

DamienMcKenna’s picture

@mstrelan: If using hook_metatag_view with the 'search_index' view mode is how other modules are doing it, then that'd be fine, thanks for taking the time to check others.

Incidentally, there's separate work for integrating search API, so I think it'd be safe to focus on just the core search module: #2692877: Add Search API support