Currently the alias for taxonomy terms is generated with <alias>/<term-name>-<term-id>, leading to ugly ids in pretty paths.
I've created a patch (or prototype) that re-uses the path alias of a term page and thus avoids term ids. The handler requires the default path pattern for taxonomy terms, which is [term:vocabulary]/[term:name]. Then the [term:name] part will be extracted and re-used in the facet alias, leading to [facet:alias]/[term:name].
I've only tested it with Search API fields, no idea if the Apache Solr module works differently ;-)
Furthermore, once the patch has been applied, the setting "Re-use term aliases for taxonomy term fields" needs to be activated in the Facet API Pretty Paths settings and the cache needs to be cleared.
Comments
Comment #1
mh86 commentedComment #2
nick_vhVocbulary? typo ;-)
pretty paths should work for both so specific search api logic would undo that.
Apachesolr takes the regular field as 1 facet value. Can you perhaps make this explode optional? Is there a way you can make this work both ways?
Comment #3
mh86 commentedSo the Apache Solr module writes something like:
?
Then the explode function won't do any harm. If the ':' delimiter is not found, the explode function will return the whole string in the first array value.
Comment #4
mh86 commentedUpdated patch that just fixes the typo
Comment #5
nick_vhLooks good overall, I'd still change the comment so it does not appear as if only search api dependent.
Comment #6
dasjohi, thanks for figuring that out :)
i'd say "If set, the term alias..."
can't give it a throughout review atm. would be great if somebody else could provide feedback
Comment #7
mh86 commentedJust realized that the Search API field name chains are a bit more complex than I thought. A chain might be: field collection -> taxonomy field -> parents, or taxonomy field -> taxonomy field (field on taxonomy term).
So the last taxonomy field in this chain will lead to the correct vocabulary.
Updated patch that:
* fixes the extraction of term fields in Search API field name chains
* adds a comment for Apache Solr
* clears Facet API cache after the pretty path admin settings form has been saved
Comment #8
mh86 commentedReworked my last patch that allows you to activate the new taxonomy coder per facet level. Additionally the according vocabulary can be selected, in case it can't be retrieved from the field settings.
With the Search API you can index taxonomy properties that are not Field API fields. For these properties no vocabulary information exists. Furthermore certain fields or properties might be based on multiple vocabularies, so the new coder won't work anyway. That's why I think a facet setting makes more sense than a global setting.
Comment #9
mh86 commentedI've learned that loading the adapter for retrieving the facet settings within hook_facetapi_facet_info_alter() is evil as it already builds the facet settings and statically caches them, without including the alterations of the Facet API Pretty Paths module (and maybe others). Thus we have to clear the static cache of facetapi_get_enabled_facets() at the end.
Alternatively we could try to directly load the facet settings via the CTools API.
Comment #10
dasjowould be great to document what exactly is going on here: something like taxonomy/term/id is mapped to [facet alias]/[term-name alias] and thus the check count($parts) == 2
vice versa here :)
Comment #11
mh86 commentedSlightly improved comments according to #6 and #10.
Thanks for the reviews :-)
Comment #12
dasjocommitted to 7.x-1.x, thanks!
Comment #13.0
(not verified) commentedFixed
<alias>/<term-name>-<term-id>