Displaying hierarchical categories in autocomplete search #759
Comments
Having the same problem, multiple categories showing up, having the same name (normal hierarchy for clothing estores men/jackets woman/jackets children/jackets). Looking for a good solution for this. |
If anybody could provide a fix for this issue, that would be splendid. |
Tried to open a discord about this, but no one is responding - https://discourse.algolia.com/t/displaying-woocommerce-product-categories-with-parents/5275 |
Hi everyone, This sounds like a bug, however I don't think we've recently touched the indexing of taxonomies. @yratof is there any chance you could send a quick email to support@algolia.com by providing us read access to your Algolia account? Please note that my above assumptions were based on my first understanding of your issue. https://www.algolia.com/users/edit#?tab=access-control This will allow me to troubleshoot this. Also, it seems that in the meantime you've disabled Algolia on the staging website, could you turn it back on so that I could observe the issue? Thank you for your patience. |
Sure thing, I turned it off because I've gone live with the current working version & didn't want to eat too much into the quota. Will enable now & shoot over an email with read access |
Everything sent over & reactivated now @rayrutjes, you can see the problem when searching for |
I took a look and see that: By default we only display the term name. I think the easiest here would be to index the full breadcrumb at indexing time. You could leverage the Implementation of the generation of the breadcrumb is left for implementation though. Let me know how it works out for you. |
Actually I tried something like this, but I couldn't get it to index, perhaps you can see the problem: add_filter( 'algolia_term_product_cat_record', 'get_term_hierarchy', 10, 2 );
function get_term_hierarchy( $record, $item ) {
$tax = $item->taxonomy;
$terms = get_the_terms( $item->term_id, $tax );
$ancestors = [];
// Check we have terms
if ( $terms && ! is_wp_error( $terms ) ) {
$ancestors = array_reverse( get_ancestors( $terms[0]->term_id, $tax ));
// Check if has parent
if ( $ancestors ) {
foreach ( $ancestors as $ancestor ) {
$parent = get_term( $ancestor, $tax );
// Check parent is term
if( $parent && ! is_wp_error( $parent ) ) {
// Add to array
$ancestors[] = $parent->name;
}
}
$record['breadcrumb_hierarchy'] = implode( ' > ', $ancestors ) . ' > ' . $terms[0]->name;
}
}
return $record;
} This is often not getting any terms or items from the filter |
You could maybe inspire from this: https://github.com/algolia/algoliasearch-wordpress/blob/master/includes/class-algolia-utils.php#L56 Not sure to see what's wrong with your implementation. |
What causes me more problems is displaying this data within the |
If you are not using the default Could that work in your case? |
I think it would work, it's not the cleanest solution, but you're right, saving the parent & the child to the name allows me to fake it. It would be a nice feature to incorporate going forward though, as this is a problem with a few of our sites currently |
Q: How can we show a breadcrumb of categories in the autocomplete. ie: Men > Summertime > Jackets rather than just Jackets
What did you expect to happen?
When Searching for "trousers", the results for the categories should bring back:
What happened instead?
Slightly confusing because these are actually supposed to be separate categories, but algolia only brings back the lowest category:
How can we reproduce this behaviour?
Create several categories, then give each a child of the same name. Add categories to your autocomplete search and see the list of "Trouser
Can you provide a link to a page which shows this issue?
https://fjellr-2255.rask22.raskesider.no/fjellrevenshop/
Technical info
The text was updated successfully, but these errors were encountered: