Let’s say I have a large set of data within which each datum has several searchable columns (e.g. Color, Height, Width, etc) such that a user could issue searches like ‘all Red items’ or ‘all Green items with width under 50’.
Is there an established algorithm that would enable me to vary the sort order of a result set based on how many times a given item within the result set has already been returned for the same search criteria? I am looking for some sort of ‘fairness’ algorithm so that I can evenly distribute the frequency with which any given item in a result set is viewed early within that set. In other words, each item in the result set should have an equal probability of appearing as the first item in the result set.
Additionally for a given user/session, the sort order of the result set would have to be maintained such that paging, additional sorting, or further filtering within the set would first respect the algorithmic ‘fairness’ sort order, then apply any additional search filters.
I’ll be implementing this in an MVC.NET website with C# back-end and SQL 2008 database. Platform-specific solutions are of course welcome, but in general, I am wondering if there is an established algorithm. I also find that my vocabulary for describing the problem is limited, so any pointers for what I could even be searching the web for would be helpful.
In some sense, I am hoping to sort the items randomly each time they are queried only I would like to preserve that particular ‘randomness’ for the lifetime of that user’s session
Sounds like you could potentially generate a random seed on login (or session creation), store that in the user’s session, then create a new
Randomusing that seed every time you shuffle the results. That’s likely to be the simplest way of doing it.On the other hand, it won’t preserve the order if the query results change. For example, if the values ABCDE end up as “ABDCE” then if the query is changed to exclude A, the same seed could easily give “BCED” as the shuffled version.