Search And Filter Bundle for eZ Publish 5

By Ivo Lukač -

As we started to work more and more on the eZ Publish new stack and Symfony framework some generic code started to pop out. One of the first examples is the Netgen Search And Filter Bundle which we shared on github. Its an eZ Publish 5 solution for configuring pages with custom searching and filtering. 

In a recent post I explained we need to take the hybrid approach when developing with eZ Publish 5. In short, there are lots of new features available only in new stack (version 5.3 was released this week), but some are still missing, hence a fallback to legacy is needed.

For one of our first eZ Publish 5 projects we needed to implement an advanced search form with filters. We could just use the legacy knowhow and build it but that would be to dull :)

We wanted to try out the new stack, and also some generic Symfony features like Forms. Of course, we soon ran into a problem. Solr search support is still not very well supported so a fallback to legacy ezfind extension was needed.

After some brainstorming we decided to create a bundle which will use Symfony Forms and be able to call legacy or new stack when searching. The result is the bundle we pushed to Github for community to try it out. It features:  

  • Search Adapter Service with paging (using PagerFanta)
  • Form building based on Symfony Forms
  • Extensible Handlers, Criterion Builders and Result Converters
  • Handlers for legacy standard search, ezfind legacy search and eZ5 Public API search
  • Result converter for legacy search 
  • Controller for handling route or location based searches
  • Basic Search example with form and criteria builder classes

Follow installation instructions for trying it out: github.com/netgen/netgensearchandfilterbundle/blob/master/Resources/doc/INSTALL.md

To make your own advanced search you could:

  1. build your own form as a Symfony Form type
  2. create your custom criteria builder as a service (it can use the public API or be legacy based)
  3. create the form template in Twig
  4. configure the search service and the appropriate route (either static one or location based)

netgen_search_filter.[location|route]_[locationid|context]:
    class: Netgen\SearchAndFilterBundle\Components\SearchAdapter
    arguments:
        - @netgen_search_filter.handler.[default|legacy|ezfind]
        - YOUR_FORM_TYPE_SERVICE
        - @form.factory
        - YOUR_CRITERIA_BUILDER_SERVICE
        - @netgen_search_filter.result_converter.[default|legacy]
        - NetgenSearchAndFilterBundle::[location|route]_search_results.html.twig
        - YOUR_FORM_TEMPLATE
        - %netgen_search_filter.page_limit%

And that should be it :)

If needed, you could also:

  • make your own handler
  • make your own result converter
  • make your own search result template

One the main ideas behind this generic bundle is to be able to build future friendly implementations. If you currently need ezfind, just use the appropriate handler and build your criterions. At later stage, when will the public API support everything that you need, just use the default handler and change the criterions.

Feel free to share some feedback here or on Github.

Comments

This site uses cookies. Some of these cookies are essential, while others help us improve your experience by providing insights into how the site is being used. For more detailed information on the cookies we use, please check our Privacy Policy.