I have a product listing service, and it will give a list of products for the logged-in users, and the list is paginated, with ten products per page. I implemented this pagination using MySQL
Recently I got a requirement to integrate it with a relevancy service; this service will give product attributes relevant to the currently logged-in user. I need to sort the products based on relevancy to the user.
var page_no = 0; var url = "https://relevancy-service-url" var query = "SELECT * FROM products LIMIT 10 OFFSET page_no;" var product_list = query -> fetch var relevent_attributes = api -> get(url, user_id)
here relevent_attributes is an array containing items in the following format:
[attribite_1 : 40, attribute_2: 20, attribute_3: 10, attribute_4: 3]
Here the key is the attribute name, and the value is the ranking. Based on the attribute ranking, I need to sort the product list.
What is the best way of sorting this list?