WebDevStudios/wp-search-with-algolia

filterOnly when declaring attributesForFaceting

amrutadotorg opened this issue · 2 comments

Hi, I would like to set filterOnly for taxonomies and wpml.native.name when declaring your attributesForFaceting

how to do it?

thank you

function algolia_add_attributes( array $settings ) {
    $settings['attributesForFaceting'] = [];
    $settings['searchableAttributes'] = [];
    $settings['customRanking'] = [];
    $settings['attributesForFaceting'][] = 'post_talk_duration';
    $settings['attributesForFaceting'][] = 'post_year';
    $settings['attributesForFaceting'][] = 'taxonomies';
    $settings['attributesForFaceting'][] = 'taxonomies_hierarchical';
    $settings['attributesForFaceting'][] = 'wpml.native_name';
    $settings['attributesForFaceting'][] = 'post_type_label';
    $settings['searchableAttributes'][] = 'post_year';
    $settings['searchableAttributes'][] = 'unordered(post_title)';
    $settings['searchableAttributes'][] = 'post_date_formatted';
    $settings['searchableAttributes'][] = 'post_dates';
    $settings['searchableAttributes'][] = 'unordered(content)';
    $settings['searchableAttributes'][] = 'unordered(youtube)';
    $settings['searchableAttributes'][] = 'taxonomies';
    $settings['customRanking'][] = 'asc(post_year)';
    $settings['customRanking'][] = 'desc(post_title)';
    return $settings;
}
add_filter( 'algolia_searchable_posts_index_settings', 'algolia_add_attributes' );
add_filter( 'algolia_posts_index_settings', 'algolia_add_attributes' );

Based on the example below, sourced from https://www.algolia.com/doc/api-reference/api-parameters/attributesForFaceting/ you'd want to do something like this.

$settings['attributesForFaceting'][] = 'filterOnly(taxonomies)';
$settings['attributesForFaceting'][] = 'filterOnly(wpml.native_name)';

Example from the link:

'attributesForFaceting' => [
  'attribute1',
  'filterOnly(attribute2)',
  'searchable(attribute3)',
  'afterDistinct(attribute4)',
  'afterDistinct(searchable(attribute5))'
]

Thank you