For the most part, I agree with @armarru's answer, however, the one issue I see is that you are shifting a poor performance burden from the client to the database. Presumably the database server is better equipped to handle this, and of course there is the network bandwidth associated with transmitting those results from the server to the application, but either way, SOME system is evaluating all records and filtering down to the ones you want.
The use of the %search string% wildcard prevents the use of any standard index, so you are looking at full-table scans.
But there is good news. There are two fantastic extensions that I think can help. The first is citext that will enable you to perform case-insensitive searches without a performance hit. Once you load the extension, you can make your fields datatype citext instead of text (or varchar or whatever), and searching 'ar' will also return 'Ar' without any nasty upper or lower functions. I think even ilike will clobber your index.
The second is pg_trgm which enables full wildcard searches. A normal B-tree index will support 'like%' searches but not '%like' or '%like%' searches. This extension enables indexed '%like%' searches. It's mind-blowing.
Here is an example of what those indexes look like.
CREATE INDEX Table1_ix1 on table1 using gin (Name gin_trgm_ops);
CREATE INDEX Table1_ix2 on table1 using gin (Surname gin_trgm_ops);
NOW, if you implement armarru's solution:
select * FROM Table1
WHERE Table1.Name::text LIKE '%ar%' OR Table1.Surname::text LIKE '%ar%'
The query can use the new indexes and a bitmap or condition to very quickly bring you the results without a full-table scan.
Unless we are talking trivial amounts of data, this will dwarf any performance you could possibly get by pulling all records onto the client and filtering there.
One other positive comment on armarru's answer is the the OR solution is preferred because it will perform short circuiting and not bother to evaluate the surname if the name results in a true condition.
%yM%, would you like to seeRandy Marshreturned?FULL TABLE SCAN, which internally is just a loop over the whole table... AndYES, usingCONCAT(a, b) LIKE '%%'is a waste of resources.