简体   繁体   English

在Sonata-Admin全局搜索中搜索哪些列

[英]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. Sonata Admin中的全局搜索选项将通过所有与Admin Class相关联的(doctrine2)实体进行搜索。

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). 在我的客户网站中,它似乎是通过所有VARCHAR字段(教义类型:字符串)而不是TEXT字段(教义类型:文本)进行搜索。

Does anybody know why this is, and how it can be changed? 有谁知道这是为什么,以及如何更改它?

According to sonata admin's documentation they have mentioned that global search module will search for all visible admins ie 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. 根据Sonata管理员的文档,他们提到全局搜索模块将搜索所有可见的管理员,即show_in_dashboard设置为true,并且仅在已配置管理员的configureDatagridFilters()函数中的字段中进行搜索,因此将字段添加到$datagridMapper将在Sonata admin的全局搜索中搜索admin类的$datagridMapper对象。

For example you have news admin and in configureListFields() you have 3 fields 例如,您有新闻管理员,在configureListFields()有3个字段

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

And in configureDatagridFilters() you have only name field to filter results configureDatagridFilters() ,只有名称字段可以过滤结果

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 因此,由于您已为此新闻管理员配置了过滤器,因此Sonata将仅在新闻管理员的名称字段中进行搜索,因此该过滤器也用于全局搜索管理员,除名称字段外,不会搜索其他任何字段


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. 搜索遍历管理类,并在选项global_search设置为true的情况下查找过滤器。 If you are using the SonataDoctrineORMBundle any text filter will be set to true by default. 如果您使用SonataDoctrineORMBundle,则默认情况下,任何文本过滤器都将设置为true。

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 默认情况下,sonata会查找字段描述(如果设置为字符串会自动涉及全局搜索),也可以通过在$datagridMapperadd()设置字段选项来强制字段在搜索中使用,如下所示

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

Sonata Search

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM