Php questions about multi-condition sorting of commodities ,. A product sorting function is used because it is a B2B platform. One of the main methods is as follows: weight analysis of commodity arrangement 1. remaining time of recommendation window (field window_recom): 40% of the weight 2. store favorable rating (field praise_rate ): weight of 30% 3. product shelving time (field add_time): weight of 30% ------ php about multi-condition sorting of products ,.
A product sorting function is used because it is a B2B platform.
The main method is as follows:
Product ranking weight analysis
1. remaining time of the recommendation window (field window_recom): 40% weight
2. store rating (field praise_rate): 30% of the weight
3. product shelving time (field add_time): 30% weight
---------------------
Sorting rules
1. for any product, the program will extract the remaining time of its "Recommended Window", "store ratings", and "product shelving Time", and calculate the final score based on its weight;
2. the higher the score, the higher the ranking;
-------------------------------------------
My current statement is order by window_recom * 0.4 + praise_rate * 0.3 + add_time * 0.3 DESC, which sorts all the items. However, as the number of items increases, the speed slows down.
Are there any better solutions.
------ Solution --------------------
Sort by a field that does not exist. if there are too many items, it will be strange if it is not slow.
1. set a fixed field to store calculated values and update them in real time. sort these fields in the future.
2. if the number of retrieved records is not large each time, use this condition order by window_recom DESC, praise_rate DESC, and add_time DESC to retrieve records, sort the records according to your algorithm, and then generate the cache.