Use a float for the rating in Vue InstantSearch


I’m using laravel and Vue InstantSearch for my website.

I’ve developed a rating system that calculates the average rating of a product for every review left for it.

The average of course could be: 3.5, 4.7, etc.

I was hoping to use this with the rating component, however it seams that component only works with integers not floats.

Is there a way to use that component with a float ?

Alternatively I’m ok with rounding the average for the rating component so that it works.

However the component fetches the data from Algolia using the “attribute-name” field; meaning I can’t use JavaScript to round the float.

I can’t round the float before I send it to Algolia because I need to use the float figure to display the star ratings on the products in the search e.g a rating of 4.5 would display 4 and a half stars out of 5.

Any ideas or help?

I’d really appreciate it, thanks in advance.

In v2, ais-rating-menu works with float values without issue:

In fact, I’m trying it out in v1 now, and it also works with float values in v1:

In these examples the float figure is loading on the movies in the search.

However when you start filtering with the star rating filter the movies with float ratings are not included in the search.

Type a movie title in the search bar with a float rating and then use the rating filter, even if that movie meets the requirements for the rating filter it will still be removed from the search because it is a float.

1 Like

I still need to use floats for the rating filter, as the examples above also do not work with float values.

Do you have any further ideas on how I could properly use floats for the rating filter?

I’ve tried some things out, and indeed: you’re right. Sorry for that. What you will need to do is round the value, and have a rating_rounded which is integers, and then use that one for the rating menu, using the real average for the display I the hits

1 Like

Good idea, I didn’t think of having another field stored in Algolia for the rounded rating.

Thanks for the help.