omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
252 stars 113 forks source link

Poor results or invalid search by default with entities #189

Closed pkly closed 3 years ago

pkly commented 3 years ago

Hi, I'm using the latest bundle but while hooking up text columns with my entity I noticed the results are, well, bad-ish. The fault is inside SearchCriteriaProvider, as it doesn't actually check add required '%' signs around the TextColumn classes, seems like the line 49 which says:

$search = $queryBuilder->expr()->literal($search);

Should instead say:

$search = $queryBuilder->expr()->literal($column->getRightExpr($search));

by default, instead of doing so only in global search as it's getting extremely hard to find things if you don't type in exactly what you want.

Seems to me like this behaviour should be an option instead of the default, as likely no one just gets the results they want instantly.

curry684 commented 3 years ago

This was done on purpose. Using a leading wildcard by default will always force your DBMS to do a full table scan without indexes which is going to instantly kill your server if you have tons of rows and slow typing users.

If you require this behavior it can be added/modified easily, or instruct your users to use % in search fields for wildcard searches.