Problem with search
Hello,
I'm having a strange problem with the search function. Considering I have 2 entities, user (id, username, password, email) and customer (id, name, number, description). When I try to search for a user by username or email it works like a charm, but when I try to search a customer by name it doesn't work and show me the full table as the result of the search, don't know why. My user table contains 3 users, my customer table contains 495 customers. My goal is to show the result of a search in an iframe using the search url (with query=...).
Is there any solution to this problem? And can we search by column (or class member) with the search url? Thanks in advance!
At the moment it's impossible to search only by a specific field, so if the whole table is retrieved after a search, it may mean that the words you have in the username are found somewhere else. We had an issue in the search engine some days/weeks ago, but it has been fixed in v1.4.0, are you using this version?
Regarding the search customization, I plan to allow soon to configure the entity fields on which the query is performed. I'm also thinking (although it's very probable that it won't be ultimately added) to add an option called search_query where you can write the DQL query to perform, just in case you need extreme customization.
I'm using the last version, I did an update today.
When I use src="../../admin/?action=search&entity=Purchase&query={{ customer.id }}" (to show purchases from the customer) in the iframe it seems to work (but it show me wrong lines too due to the fact we can't search by field). I don't know why it isn't working on the full table with the search form. I override layout.html.twig but I don't touch the search form in it.
Sorry for the off-topic but I also want to reopen this issue (I can't because I'm not the one who closed it): https://github.com/javiereguiluz/EasyAdminBundle/issues/253
@javiereguiluz I think that we should propose something like a "cookbook" extension of EasyAdmin on how-to customize the search action. Actually, I really think that a template + controller override is not that hard to do when you want to use a field-specific search, and it would allow users to completely change the behavior of the search action.
By this, I mean that the user can add its own search inputs, search himself on related entities, etc..
A search_query sounds too much to me, whereas a simple search_fields configuration is enough.
An extension is better if you want a bigger search engine...
I figured out the problem with search on my tables. Some of my tables contained empty "not nullable" fields on a lot of lines, this was causing this bug. My bad, so this is resolved. Waiting for a field-search function, keep up your hard work!
EDIT: Nevermind, the bug is still here for some tables, don't know why, but it's not a big deal I'll wait for an update to search by field.
@arukado-sama I've just merged #273 to allow to configure the fields used to perform the search queries:
# app/config/config.yml
easy_admin:
entities:
Customer:
class: AppBundle\Entity\Customer
search:
fields: ['firstName', 'lastName', 'email']
# ...
For now you can use it in the dev version and it will be availble in the next stable version of the bundle to be published soon.
It works, thanks for your hard work!