I am using an ais-refinement-list and running into an issue where I cannot properly control the sort-by prop. I am specifying :sort-by="['isRefined:desc', 'name:asc']" but the results are returning in the following order:
It would be helpful to be able to tell Algolia to sort these results like you would sort actual numbers, like this:
hmm, in this case you can also pass a function to sortBy to do the sorting which works for numbers yourself. Let me know if you have any trouble creating it
@Haroenv Interesting. Is there documentation on that? Or perhaps you could provide an example, so I know what arguments the function takes?
The function takes The Same arguments as the native sort function: https://community.algolia.com/vue-instantsearch/components/refinement-list.html
Thanks.
For anyone faced with a similar issue, this is how we fixed it.
First, added a sort method:
const app = new Vue({
el: '#app',
data: function() {
return {
query: ''
}
},
methods: {
numberAsc: function (a, b) {
if (a.isRefined && b.isRefined) {
return a.name.split('-')[0] - b.name.split('-')[0]
} else if (b.isRefined) {
return 1
} else if (a.isRefined) {
return -1
} else {
return a.name.split('-')[0] - b.name.split('-')[0]
}
}
},
components: {
'ais-event-wrapper': AisEventWrapper
}
});
Then referenced this sort method:
<ais-refinement-list attribute-name="attribute-name" :limit=15 :sort-by="numberAsc"></ais-refinement-list>
That's what I meant, thanks for sharing your solution!
Most helpful comment
Thanks.
For anyone faced with a similar issue, this is how we fixed it.
First, added a sort method:
Then referenced this sort method: