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.
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.
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.
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.