search.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Search
  2. ======
  3. The admin comes with a basic global search available in the upper navigation menu. The search iterates over admin class
  4. and look for filter with the option ``global_search`` set to true. If you are using the ``SonataDoctrineORMBundle``
  5. any text filter will be set to ``true`` by default.
  6. Customization
  7. -------------
  8. The main action is using the template ``SonataAdminBundle:Core:search.html.twig``. And each search is handled by a
  9. ``block``, the template for the block is ``SonataAdminBundle:Block:block_search_result.html.twig``.
  10. The default template values can be configured in the configuration section
  11. .. configuration-block::
  12. .. code-block:: yaml
  13. sonata_admin:
  14. templates:
  15. # other configuration options
  16. search: SonataAdminBundle:Core:search.html.twig
  17. search_result_block: SonataAdminBundle:Block:block_search_result.html.twig
  18. You can also configure the block template per admin while defining the admin:
  19. .. configuration-block::
  20. .. code-block:: xml
  21. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  22. <tag name="sonata.admin" manager_type="orm" group="Content" label="Post"/>
  23. <argument />
  24. <argument>Acme\DemoBundle\Entity\Post</argument>
  25. <argument />
  26. <call method="setTemplate">
  27. <argument>search_result_block</argument>
  28. <argument>SonataPostBundle:Block:block_search_result.html.twig</argument>
  29. </call>
  30. </service>
  31. Performance
  32. -----------
  33. The current implementation can be expensive if you have a lot of entities as the resulting query does a ``LIKE %query% OR LIKE %query%``...
  34. There is a work in progress to use an async javascript solution to better load data from the database.