• Resolved curtisagitate

    (@curtisagitate)


    I am wondering if it is possible to give categories a hierarchy within the search output?

    This post sorta explains it – https://stackoverflow.com/questions/35310819/algolia-woocommerce-hierarchical-indexing-of-categories

    Effectively would want products in category X to always be shown last regardless of relevance so to speak.

    So the output would first show all products that match relevancy criteria and are in categories A, B and C…. Then if applicable show any remaining products that match relevancy from category X

    My assumption is that I would use either, algolia_terms_index_settings or algolia_terms_{$taxonomy}_index_settings to achieve this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    hmm, that’s feeling most like something that would need to be done within the Algolia index configuration more than anything specific with the plugin itself. Though I’m not sure how to potentially achieve that either, within the dashboard. Never attempted such things with placing specific condition results last.

    Thread Starter curtisagitate

    (@curtisagitate)

    Thanks, I was under the impression that any settings configured within Algolia will be overridden by your plugin when you index?

    Is that not the case if I were to config this Alogolia’s end?

    Thread Starter curtisagitate

    (@curtisagitate)

    Just been thinking about this and come up with a different way to achieve the same thing, I think.

    First I have added a new attribute called ‘Ranking Importance’ and set this to 1 or 2 based on category.

    
    

    //ranking priority
    $terms = get_the_terms( $post->ID, ‘product_cat’ );
    foreach ($terms as $term) {
    $product_cat_id = $term->term_id;
    if($product_cat_id == ’22’) {
    $ranking = 2000;
    }
    else {
    $ranking = 1;
    }
    }
    $attributes[‘ranking_importance’] = $ranking;`

    Then I have registered this as a custom ranking:

    
    

    function custom_posts_index_settings( array $settings ) {
    $custom_ranking = $settings[‘ranking_importance’];
    array_unshift( $custom_ranking, ‘asc(ranking_importance)’ );
    $settings[‘ranking_importance’] = $custom_ranking;

    return $settings;
    }

    add_filter( ‘algolia_posts_index_settings’, ‘custom_posts_index_settings’ );`
    `

    Note: Set to 2000 due to weighting – https://www.algolia.com/doc/guides/managing-results/must-do/custom-ranking/how-to/controlling-custom-ranking-metrics-precision/

    As I understand it, this should have worked. I can see the new attribute in Algolia but it seems the custom ranking function has had 0 impact.

    Any thoughts?

    Thread Starter curtisagitate

    (@curtisagitate)

    Further to my other message, just for anyone else’s benefit trying to attempt this same thing.

    All I had to do further to my last work was update the order of the ranking and sorting attributes within Algolia directly. Pushing this custom ranking to the top of the list has got this working.

    Not sure why, I was under the impression any settings configured within Alogolia would be overridden by the plugin – swear I read that on some piece of documentation. But I have pushed settings and reindexed within the plugin and it doesn’t appear to have overridden this ??

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I was under the impression that any settings configured within Algolia will be overridden by your plugin when you index?

    I believe only when you press buttons to push up settings, not the indexing themselves.

    The plugin offers the ability to bulk re-index your content, and then also push up setting customizations. Or at least should be with that last part. Depends on how you do that, and if the code has actually changed defaults.

    Sounds like you’re in a good spot, nonetheless.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘hierarchical indexing of categories’ is closed to new replies.