fixing the postgres search to avoid duplicates