Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What columns get searched in Sonata-Admin global search

The global search option in Sonata Admin searches trough all the (doctrine2) entities that have Admin Classes associated with them.

What I am trying to figure out is how to configure what columns get searched by the global search. In my clients website it seems to be searching trough all VARCHAR fields (doctrine type: string) and not the TEXT fields (doctrine type: text).

Does anybody know why this is, and how it can be changed?

like image 859
vitrus Avatar asked Sep 18 '14 09:09

vitrus


1 Answers

According to sonata admin's documentation they have mentioned that global search module will search for all visible admins i.e show_in_dashboard is set to true, and it will search in only those fields which are in configured admin's configureDatagridFilters() function only,So the fields added to $datagridMapper object of admin class will be searched in Sonata admin's global search.

For example you have news admin and in configureListFields() you have 3 fields

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('id')
        ->add('name')
        ->add('createdDate');
}

And in configureDatagridFilters() you have only name field to filter results

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper->add('name');
}

So Sonata will search in only name field of your news admin because you have configured a filter for this admin,So this filter is also used in global search for admin and no other field will be searched except name field


According to docs

The "global search" allows the end user to iterate over all visible admins in the dashboard and search for the keyword. The current implementation is very simple, every filter related to a string will be searchable by default.

ADMIN BUNDLE ~ GLOBAL SEARCH


Other information regarding sonata global search is

The search iterates over admin classes and look for filter with the option global_search set to true. If you are using the SonataDoctrineORMBundle any text filter will be set to true by default.

By default sonata looks for field description if set to string it automatically involves in global search you can also force field to be used in search by setting field option in $datagridMapper's add()like below

->add('name', null, array('global_search' => true), null, array()

Sonata Search

like image 150
M Khalid Junaid Avatar answered Oct 16 '22 19:10

M Khalid Junaid