Linking taxonomy to content types

I've been working on a few custom types recently that needed their own custom vocabularies.

Was wondering if anybody was perhaps working on a way to assign GitHub - collective/collective.taxonomy: Create, edit and use hierarchical taxonomies in Plone! · GitHub (GitHub - eea/volto-taxonomy: Volto integration with collective.taxonomy · GitHub) fields to a content type.

I'm hoping this would make it easier to extend content types to include fields where Editors can manage categorization in ways other than just using tags. For example add a type and a region or info that comes from a vocabulary (list).

Anybody working on this kind of extension?

Or perhaps have other solutions that they've implemented in the past that works more easily that creating custom types every time?

When creating a taxonomy, the product creates a behavior that includes a field with that taxonomy. Then you need to assign the taxonomy to your content-type and you're done.

1 Like

Thank you! I was hoping it would be this easy, but didn't actually realise that is was. This is exactly what I needed for this project. Thanks @erral for your response and saving me a lot (A LOT) of time.

It makes sense if you've editors that update the vocabolaries/taxonomies. If they're almost fixed, it is a layer you will use a little.

Follow-up: Making collective.taxonomy terms searchable as full text

Following on from the above: while working through a content architecture problem, I found that taxonomy field values should be searchable as plain text, not just usable as facets. This would help a user find items no matter how they search. Also, it then works in the main search, not just in a search block.

The issue is straightforward: taxonomy fields store tokens on the object, not human-readable titles. Those tokens never make it into SearchableText, so a visitor searching for "teacher development" won't match a resource tagged with a "Teacher Development" taxonomy term. The fix is a SearchableText indexer that resolves tokens back to their titles via the taxonomy utility and concatenates them into the index.

Has anyone already solved this, or is there something in collective.taxonomy itself that addresses it that I'm missing?

Thanks @yurj but this doesn't resolve the searchable text issue, as it only indexes it as a keyword index from what I am seeing. What would need to bridge the gap here is something that operates almost like the indexer for Dexterity items that indexes new fields when marked as searchable.

Ideally something that uses IDynamicTextIndexExtender from collective.dexteritytextindexer to resolve taxonomy tokens to their human-readable titles and contribute them to SearchableText (or a similar mechanism built into collective.taxonomy itself as an opt-in option, seeing as making it not searchable text was a decision and not an oversight).

Hi Karel,

I’m not sure that I understand your use case. My first instinct was to point out that generally speaking you can add any field as a behavior to extend your content type – i.e. similar to Mikel’s reply. I am guessing that collective.taxonomy also uses this mechanism (?).

Other add-ons that might serve as inspiration: collective.glossary and collective.z3cform.dgftreeselect

You mean like how “Subject” keywords are stored in the portal_catalog? I would not use SearchableText for this. Keep it separate, add a KeywordIndex, FieldIndex (or something better suited) and Metadata for “TaxonomyTree” or something along those lines.

If you expect your visitors to frequently use Taxonomies to search for content, then you can build an ui that makes this possible. Perhaps there might be a package for this that builds on eea.facetednavigation (archived). Or, you can roll your own using a widget that supports autocomplete, like plone.app.z3cform.widgets.select.AjaxSelectFieldWidget

Thanks @mtrebron - some real food for thought.

The reason for collective.taxonomy being my preferred choice for this, is because it already does 90% of what we need.

The use case would be where we add an associate and allow the Editor to select their field of study from a list that is created through the taxonomies. That way we can also use a facet in the associate search that allows them to narrow the search down.

However, we know that some users might rather want to just type in the field of study (either in the main site search or the associate search block) and expect a list of associates in that field.

So it feels like just extending that taxonomy to a text search is the shortest route without expecting the Editor to add duplicate info. It also makes the taxonomy manageable by the site Editors in case new fields of study names need to be added to the list of available options.

I hope this helps explain the direction of this kind of project.

Thanks, that gave me some more ideas:

Like you already mentioned, the mechanism that Dexterity uses (used? I think I read something about it being the default now), to add field content to SearchableText is something that you can piggyback on.

    urprodukt_code = schema.TextLine(
        title=_(u'Urprodukt Kürzel'),
        description=_(u'Beim Eintragen beachten, dass das Kürzel einzigartig ist'),
        required=True,
        min_length=6,
        max_length=6,
    )
    directives.widget(
        'urprodukt_code',
        AjaxSelectFieldWidget,
        vocabulary='plone.app.vocabularies.Keywords',
        pattern_options={"maximumSelectionSize": 1},
        allowNewItems=True,
    )
    dexteritytextindexer.searchable('urprodukt_code')

Practically speaking, I can’t really help you there: I remember adding this to a Plone 5.0 site once. It let me search for formulation or article ids and find the documents that referred to those. Upgrading to Plone 5.1 broke it, and life went on without the feature that nobody besides me had ever thought of using :slight_smile: I do remember that a catalog rebuild did not fix the bug.

For the UX, you could think of implementing a viewlet that replaces the current searchbox and injects something that searches your taxonomy vocabulary (if possible – I “think” I remember not using collective.taxonomy at the time because I could not easily get to the actual data).

I have circled this topic on many occasions but never found the holy grail. Potential strategy may include searching a NamedVocabulary, VocabularySource, REST endpoint or plain JSON for the terms that your user is typing, and offering these up in your results. Heavy customization territory, I don’t know if your project budget supports such a deep dive...

Keep us posted on your progress!

1 Like

Just a quick thought on this: making taxonomy titles (not tokens) searchable is a really good idea to implement in collective.taxonomy ... but keep in mind: multilanguage sites. The taxonomy trees are translatable and you need to index the correct taxonomy language on your content. But with indexer adapters, this should be straight forward. But it would be cool, if you can activate "add taxonomy to searchable text" as a checkbox on the taxo config and the let the adapter do its work ...

1 Like

Thanks @petschki

I think this is one of the reasons for specifically looking at collective.taxonomy. It works very well with multilingual, so that will definitely part of the consideration when adding anything.

But what about the "add the field to searchable text" behaviour (plone.textindexer)? It seems a clash with this "add taxonomy to searchable text". Can't the field just implement things so plone.textindexer works?

Hi @yurj. These feel like they refer to two separate problems. plone.textindexer works well for plain Dexterity fields and we'd use it for those. The taxonomy case is different because the value stored on the object is a token, not readable text. So plone.textindexer would index the token as-is, which isn't useful for free-text search. The missing piece is specifically the resolution from token to human-readable title before contributing to SearchableText, which plone.textindexer has no mechanism for.

if you implement "IDexterityTextIndexFieldConverter", it should the work for you.

2 Likes

I would register a custom indexer that resolve the taxonomy tokens to text...

see a blueprint:

be aware, this is now in the plone core, the imports are changed

1 Like