The Combine fields filter in Drupal Views

How to search content across multiple content types and multiple fields.

On a recent Drupal site, a key requirement was to provide the ability for end users to be able to filter a set of results based on free text keywords. To many, this may seem like a complicated requirement which could involve days or weeks of custom development. With Drupal Views, the correct data model, and the Global: Combine fields filter, this is all achievable with just some configuration and no development whatsoever.

Firstly, like with any Drupal project, you need to ensure you have planned out your data model. You need to decide which fields you want to be searchable as these will need to be defined in your Drupal View later.

IMPORTANT: you can’t use the main Body field of a Content Type, as this is a special field (it combines Summary and Body), which the combine fields filter can’t search on. The combine fields filter can only search in Text field types without the Summary.

In this example, I have 2 fields: Title and Content. Body is being made redundant to make way for a field that can be searched: Content.

dan_fields_articles_01.jpg

Secondly, you need to ensure that your View is usings Fields formatting, and not Content formatting, as you need to add each individual field so that they can be combined using the combine fields filter.

dan_fields_articles_03.jpg

Thirdly, you need to configure the Global: Combine fields filter (as demonstrated in the screenshot below) and expose the filter. This can only be used with a Views Page, not a Views Block, as exposed filters do render using a Views Block.

dan_fields_articles_02.jpg

You now have a fully working in-page search to filter content listings. You can off course add additional content filters and sorting criteria, such as alphabetical and date created. Pretty quickly you can build up a very powerful in-page search feature, all using the power of Drupal Views.

To conclude, this solution isn’t suitable for large scale searching or if using a large number of fields, due to adding additional overhead to the database query. At this point, it would be advisable to use Drupal’s Search API module and a 3rd party search engine (e.g. Elasticsearch).

But as a Drupal configurator, it is very convenient to be able to achieve this basic search requirement using Drupal Views, rather than needing to invest in development time.

Performance Max new features

Performance Max new features

As we head into the business end of Q4, it’s more important than ever to get better performance from your digital marketing campaigns. One way to do that is through utilising Performance Max campaigns and especially the new features.

Our commitment to supporting Drupal and Drupal 10

Our commitment to supporting Drupal and Drupal 10

As a Drupal Association Organisation Member, we’ve been proud supporters of Drupal for many years and Drupal is our go to CMS for many of our web development clients. When new Drupal releases launch, we’re often busy helping clients plan their upgrade path and with Drupal 10 launching in December, it’s a busy end to the year for our web development teams.

Let's chat. Tell us a bit about your project.

 If you prefer to speak with someone, call 01202 203160 or if you'd like to book a 30 min meeting to see if we can help just let us know and we'll arrange a call with one of our Directors.