The solution is pretty simple, but often skipped:
1) The reason for every search should be required and logged by the searcher.
2) The logs be randomly spot-checked by an auditor(s) who verifies the reasons given by interviewing the person(s) who searched.
But to check it the auditors need detailed access to the records. So who audits THEM?
This kind of question has been asked repeatedly since at least the Roman Empire.
(The U.S. answer to "Who guards the guardians?" , at least for direct abuse of person under color of law, is the Fourth and Fifth amendments and the "fruit of the poisoned tree" doctrine: Fail to follow the law and you don't get a conviction, because misbehaving police are FAR more of a problem for the population than even a lot of violent private-enterprise crooks going back to work. But while it does reduce the incentive, it doesn't block the behavior.)