That darn taxonomy widget

I'm working on a project where one of the main features is the ability to specify a manufacturer, model and series of aircraft, based on the standard ICAO taxonomy.

The Problem

Unfortunately, the Drupal taxonomy system is completely unequipped to deal with a taxonomy this large. The reason stems from the fact that Drupal deals with the entire information set at once, specifically in these three contexts:

  1. taxonomy_get_tree. This function is horribly slow for large taxonomies. It should only be called whenever it is necessary to see the whole taxonomy tree at once, which in my case, for this project, is never.
  2. The taxonomy select, wire transfer. When asking the user to choose terms from the taxonomy, Drupal only makes the HTML select widget available. Building 10,000 <option> tags and moving them over the wire to the browser is silly.
  3. Choosing terms. Once the tree has been built, moved to the browser (and rendered by the browser -- also slow), the user has to find what s/he is looking for. This you can just forget... it doesn't work. When looking through 10,000 options, you will never find the one you need.

The Solution

I don't profess to have the final or best solution to this problem, but for this project I have built an AJAX powered selection widget that avoids all three of the above problems. First, it never calls taxonomy_get_tree and never processes the entire data set on the server. Second, since only a small subset of the available terms are sent over the wire into the browser, transfer and rendering times are also short. Finally, since the user is only presented with the next most logical subset of information, making a selection is easy.

This solution required a change to the taxonomy module, however. It required that the taxonomy_form function gets a themable widget back, instead of the entire, completely built, HTML select box. The rationale for this should be clear; if you don't need the HTML select box, don't build it.

The changes to the taxonomy module can be seen in the issue queue. The first patch by Chx that actually got committed misses the important point about not building the select widget before getting to the themable part.

I'm hoping that this patch will make 4.7, so any reviews and testing are very welcome.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options