Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Display Search Results With Search API Views

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:04
    So far, in our fish finder application,
  • 0:06
    when we've displayed search results,
  • 0:09
    we've done so with the fairly generic Search API pages display.
  • 0:13
    However, the Search API module has really good integration with the views module.
  • 0:18
    This is one of my favorite things about the module,
  • 0:20
    and it's actually one of the reasons why I chose Search API
  • 0:22
    in the first place for the implementation of search on Drupalize.Me
  • 0:26
    and some various other projects.
  • 0:28
    By combining Search API with the power of views,
  • 0:30
    we gain a lot of flexibility and the ability to display things in many different ways.

Display Search Results With Search API Views

Loading...

Being able to display search results using the Views module provides a huge amount of flexibility with respect to what is listed, what it looks like, and more. In this tutorial we'll look at using the Search API Views module, included in the Search API project, to create a view that allows users to search our Solr index and display the results as a table, or really, in any other way that Views can display content. We'll also cover some special considerations regarding access control and entity relationships that we need to keep in mind when using Views to display search results.

The biggest difference between creating a view that lists a bunch of nodes, and one that displays search results is that you need to use your Search API index as the base table from which you're building your view. Then, by default, the view only has access to the fields that are in the Solr index. This allows you to build the entire view without having to query the database. Or you can use the Views module's ability to define relationships to other buckets of content to query the database and pull in additional information. There's a huge amount of flexibility.

When building views from the Solr index you can optionally expose one or more filters. Essentially creating a form that allows someone to construct a search query. This can be as simple as exposing a keyword text field, or as complex as you would like to get. We'll look at using exposed filters to create a form that users can perform a search with and create a more complete search experience. We'll also look at how you can move those exposed filters into a block that can be displayed on the home page of our site, allowing us to replace the functionality provided to the Drupal core Search module with Views and Solr.

By the end of this tutorial you should be able to create a view that displays search results using the Search API Views module.

Downloads: 
Log in or sign up to download companion files.
Additional resources: