There is the ability to assign taxonomy reference fields to custom entities, but they are not indexed in the same way that taxonomy references are when they're attached to nodes.

For module developers who wish to make use of taxonomy terms it would be useful to index them using the taxonomy_index table in the database. This would be a simple change, removing nid and adding entity_type and entity_id.

Comments

dave reid’s picture

Version: 7.0 » 8.x-dev

I have written http://drupal.org/project/taxonomy_entity_index in the meantime. This can only be a 8.x issue since we have to change schema.

EvanDonovan’s picture

Excellent idea - I was just looking for this.

andypost’s picture

xjm’s picture

Just a note, #1050466: The taxonomy index should be maintained in a node hook, not a field hook and this issue are not mutually exclusive. The patch there (which is NR, hint, hint) could easily be moved to a generic entity-level hook rather than the specific node hook.

The main concern with adding entities to the index tables is size/performance/overhead, as far as I understand. catch said:

The proper solution for dealing with slow queries due to core's default field storage is either alternative field storage engines (such as mongodb or something like PBS), or something like the materialized view API. Neither of these were anywhere near core inclusion during the Drupal 7 release cycle, and {taxonomy_index} was put in as a compromise between postponing terms as fields on vapourware, vs. joining on all the possible field tables which would've been a significant performance regression. Similar tables exist in both tracker and forum modules to deal with similar problems.

I'm hopeful that the work on materialized view API as part of gsoc, or Damien's proposed document storage model for Drupal 8, would allow us to ship a proper system for this stuff in Drupal 8 rather than these one-off hacks.

So perhaps the D8 issue is really "make something better than index tables."

russellb’s picture

Since we moved to entities I can see no clear route in core to go from taxonomy to the occurrence of taxonomy on entity instances. Taxonomy data seems to be getting fragmented across fields with no path to find it. One of the great benefits of taxonomy is to allow us to find all things categorised by a particular vocabulary or term.

Is there a place where we can map a vocabulary to the places where its occurrence data is stored?

Or is that something that we need to consider now that we have lost global taxonomy indexing?

saltednut’s picture

Version: 8.x-dev » 9.x-dev

Unfortunately, it looks like we missed the boat on this for D8.

klonos’s picture

...it's a pity though because this is one of the 3 issues required to get the functionality of Taxonomy Entity Index in core so we don't require another extra module for D8. The other two issues are to be fixed in D8 so, can't we make an exception here?

jibran’s picture

Version: 9.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Active » Postponed

We can make this change in minor version.

xjm’s picture

Category: Feature request » Task
Issue tags: +D8 upgrade path

Recategorizing as a task, since there is no functional change (the start and endpoints are the same in functionality).

Partly agreed with #8. If we did the bare minimum scope (simply modifying TermStorageSchema::getEntitySchema()) then this is is a straightforward update to add the other entities to the index table. With the new automatic entity schema change handling, it might not even need an update hook (not sure). However, there is also a slight BC break -- queries that are running against this table would suddenly start selecting non-nodes unintentionally. So it's not 100% clear-cut.

The broader "fix it right" scope from #4 is also even feasible to do without BC breaks, and could also probably be developed in contrib before 8.1.x (as Taxonomy Entity Index and mv were in D7).

I do agree that this is not on the table for 8.0.x because it does not meet the criteria in the beta phase criteria.

Keep in mind that there is a workaround as well -- depending on the usecase, one can use EFQ. Or Views. Etc.

andypost’s picture

There's Materialized views API and its code looks great

fishfree’s picture

Strongly recommend Drupal 8 include this module before its release candidate publication.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

Status: Postponed » Active

Nor does this need to be postponed.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

Category: Task » Bug report

> Recategorizing as a task, since there is no functional change (the start and endpoints are the same in functionality).

Bug, surely?

Views handlers for taxonomy depth aren't available for non-node entities, so a major use case of taxonomy is node-only.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Alex Razumov’s picture

This functionality is not implemented into drupal core yet.
So taxononomy index can work right now only with nodes.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andypost’s picture

jhmnieuwenhuis’s picture

This should really be addressed now.
With media in core we should be able to use a view with a "has taxonomy term...." with media type.

I now use two modules to get results :
- media_taxonomy_filter
- taxonomy_term_depth

Regards,
Hans

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

sundhar’s picture

Solution for all entities with taxonomy filter, based on module.

entity_taxonomy

It supports all major entities like user, comments, commerce_product, paragraphs and etc...

This module maintain taxonomy_index based on entity_type.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

If https://www.drupal.org/project/drupal/issues/2429699 is merged is this ticket still relevant?

anybody’s picture

@smustgrave: Yes (sadly) it is! ;)
See https://www.drupal.org/project/taxonomy_entity_index

These issues have to be fixed accordingly:
#962664: Taxonomy Index for unpublished entities
#1040786: Include entities in taxonomy_index
#610076: Add a primary key to the {taxonomy_index} table and prevent duplicates being inserted

Currently Drupal Views are still very "Content" (node) centric in this part.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Update tag. This also needs an issue summary update.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Category: Bug report » Task

This is still a task, or even a feature request, lack of features isn't a bug. We also didn't have generic revision routes/UI until a couple of months ago years after they were theoretically possible, but those were added as features/tasks too.

It's much easier to have dynamic database tables than it was when this issue was opened, so I would suggest something like this:

1. Convert the taxonomy_index maintenance code to a service.

2. Make that service entity-generic and use per-entity-type tables (using a similar pattern to the database cache backend), that will help keep the number of rows per table somewhat under control and save having to store entity_type and querying on it.

The other option would be to port https://www.drupal.org/project/mv to Drupal 10 then propose it as an experimental module in core, and then we could drop the taxonomy_index-specific code altogether.

saltednut’s picture

Not seeing documentation around MV or much usage? Steps 1 and 2 recommended sound doable and do not require an experimental module. Converting things over to services has been a goal since we moved to this architecture so I'd lean toward supporting that.

quietone’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.