search.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Search
  2. ======
  3. The admin comes with a basic global search available in the upper navigation menu. The search iterates over admin classes
  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 also need to configure the block in the sonata block config
  19. .. configuration-block::
  20. .. code-block:: yaml
  21. sonata_block:
  22. blocks:
  23. sonata.admin.block.search_result:
  24. contexts: [admin]
  25. You can also configure the block template per admin while defining the admin:
  26. .. configuration-block::
  27. .. code-block:: xml
  28. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  29. <tag name="sonata.admin" manager_type="orm" group="Content" label="Post"/>
  30. <argument />
  31. <argument>Acme\DemoBundle\Entity\Post</argument>
  32. <argument />
  33. <call method="setTemplate">
  34. <argument>search_result_block</argument>
  35. <argument>SonataPostBundle:Block:block_search_result.html.twig</argument>
  36. </call>
  37. </service>
  38. Performance
  39. -----------
  40. The current implementation can be expensive if you have a lot of entities as the resulting query does a ``LIKE %query% OR LIKE %query%``...
  41. There is a work in progress to use an async javascript solution to better load data from the database.