using a catch instead of a transaction (which would hang) to get results count, this means that if one search is bad it doesn't break a users search page
This might sound funny by db_nextval has given me the same value twice on our system resulting in commit errors, therefore I put some extra precautions into the code. Hopefully it will not be necessary in the future as it fixes the symptoms and not the roots, but for the time being it is the best we got
adding code to prevent infinit loops on searches within searches and catching errors on contact search conditions so that one bad condition doesn't break the contact searches page