You could implement some kind of search algorithm with a sorting algorithm. I have been meaning to write something for this but essentially make use of logarithmic functions to query a database. I know this is a challenge since database queries get in the way of actually writing functional searches. Possibly what you could do are unique searches on indexed items in your table and create an join a subtable and then search that table so you wont have any time out issues. Just an idea it might not even be a good one.