Closed alishanster closed 6 years ago
Here is what I have in instantsearch.php:
search.addWidget(
instantsearch.widgets.rangeSlider({
container: '#aligolia-price',
attributeName: 'price',
templates: {
header: '<h3 class="widgettitle">Price</h3>'
},
tooltips: {
format: function(rawValue) {
return 'OMR' + Math.round(rawValue).toLocaleString();
}
}
})
);
Upd. I also added attributesForFaceting to function my_posts_index_settings( $settings ), still no luck...
add_filter( 'algolia_posts_listings_index_settings', 'my_posts_index_settings' );
// We could also have used a more general hook 'algolia_posts_index_settings',
// but in that case we would have needed to add a check on the post type
// to ensure we only adjust settings for the 'listings' post_type.
/**
* @param array $settings
*
* @return array
*/
function my_posts_index_settings( $settings ) {
// Make Algolia search into the 'price' field when searching for results.
// Using ordered instead of unordered would make words matching in the beginning of the attribute
// make the record score higher.
// @see https://www.algolia.com/doc/api-client/ruby/parameters#attributestoindex
$settings['attributesToIndex'][] = 'unordered(engine)';
$settings['attributesToIndex'][] = 'unordered(price)';
$settings['attributesToIndex'][] = 'unordered(mileage)';
// Make Algolia return a pre-computed snippet of 50 chars as part of the result set.
// @see https://www.algolia.com/doc/api-client/ruby/parameters#attributestohighlight
$settings['attributesToSnippet'][] = 'engine:50';
$settings['attributesToSnippet'][] = 'price:50';
$settings['attributesToSnippet'][] = 'mileage:50';
$settings['attributesForFaceting'][] = 'price';
$settings['attributesForFaceting'][] = 'mileage';
// Always return the value we are filtering.
return $settings;
}
The slider seems to be working now, doesn't it?
Yes! Thank you guys for the help. I had to declare attributesForFaceting not only to my custom post type index (posts_listing), but to searchable_posts index as well. In other words just add another filter:
add_filter( 'algolia_searchable_posts_index_settings', 'my_posts_index_settings' );
What did you expect to happen?
Working rangeSlider for prices.
What happened instead?
rangeSlider widget not showing up
How can we reproduce this behavior?
Create custom post types with post meta fields, push post meta fields to Algolia, make meta fields searchable. I also integrated those fields into a custom ranking. I was not using ACF plugin so I simply replaced get_field() to (float) get_post_meta( $post->ID, 'price', true ); .
Note: when I do console.log(data), the price attribute is showing and it is a numeric value
Can you provide a link to a page which shows this issue?
http://carz.stylemix.biz/?s=
Technical info