My setup is the following:

- A taxonomy 'expertises' with some terms
- A few hundred users with a term_reference field to their expertise
- An overview using Search API SOLR and FacetAPI to filter users on their expertise

All works fine. However, when I delete a term, Search API doesn't see that it needs to re-index the user entities. The filter remains visible (although now by showing the term ID instead of its label), until I totally clear the index and re-index.

Am I doing something wrong or is this a bug?

Comments

drunken monkey’s picture

Title: Deleting terms doesn't delete them from the index » Deleting taxonomy terms doesn't update entities with term reference fields
Project: Search API » Drupal core
Version: 7.x-1.x-dev » 7.x-dev
Component: Framework » taxonomy.module

It is a bug, but I'd rather say it's one in Drupal core. When a taxonomy term is deleted, I'd say that term reference fields should be updated accordingly and the entity update hook of the parent entity called. This doesn't seem to be the case at the moment, however.

A correct handling of this case in Drupal core would solve your problem, as Search API observes these general hooks, instead of trying to find out the implications of specific actions (like deleting terms).

BarisW’s picture

Hmm, I thought Drupal core already handles this using hook_taxonomy_term_delete?
When a term is deleted, the entry in the table 'taxonomy_index' is deleted as well.

However, the search index doesn't gets updated. Even if this is core bug, what would be the way for me to do this in my own module?

drunken monkey’s picture

You could implement hook_taxonomy_term_delete() (preferably in a way such that it executes before taxonomy_taxonomy_term_delete()) and manually delete references to that term from all nodes which include one (you can use the taxonomy_index table for that, if your hook implementation is called before taxonomy_taxonomy_term_delete()). This should also trigger hook_entity_update() for those nodes, fixing this problem.

Another way would be to use Rules to mark nodes as "dirty" (i.e., needing indexing) when taxonomy terms they reference are deleted. Don't know how well that would work, though.

David_Rothstein’s picture