search.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # app/config/config.yml
  14. sonata_admin:
  15. templates:
  16. # other configuration options
  17. search: SonataAdminBundle:Core:search.html.twig
  18. search_result_block: SonataAdminBundle:Block:block_search_result.html.twig
  19. You also need to configure the block in the sonata block config
  20. .. configuration-block::
  21. .. code-block:: yaml
  22. # app/config/config.yml
  23. sonata_block:
  24. blocks:
  25. sonata.admin.block.search_result:
  26. contexts: [admin]
  27. You can also configure the block template per admin while defining the admin:
  28. .. configuration-block::
  29. .. code-block:: xml
  30. <service id="app.admin.post" class="AppBundle\Admin\PostAdmin">
  31. <tag name="sonata.admin" manager_type="orm" group="Content" label="Post" />
  32. <argument />
  33. <argument>AppBundle\Entity\Post</argument>
  34. <argument />
  35. <call method="setTemplate">
  36. <argument>search_result_block</argument>
  37. <argument>SonataPostBundle:Block:block_search_result.html.twig</argument>
  38. </call>
  39. </service>
  40. Performance
  41. -----------
  42. The current implementation can be expensive if you have a lot of entities as the resulting query does a ``LIKE %query% OR LIKE %query%``...
  43. .. note::
  44. There is a work in progress to use an async JavaScript solution to better load data from the database.