Create a search view that doesn’t load entities from the database

Last updated on
29 November 2023

Views created by the Search API will, by default, load the entities/items contained in the result set from the database to display them in the view (either as fields or entities rendered with a view mode). While this is often the desired behavior, and can’t be avoided in other cases, if you’re using Solr, which is already able to return field values in the result, you might prefer using Solr’s field values instead and avoiding any entity loads from the database.

Unfortunately, there’s several things that could lead to entity loads in your view, so getting this right is a bit tricky. This is a list of settings you should pay attention to:

  • You need to be using Search API 8.x-1.12 or higher.
  • Enable “Retrieve result data from Solr” in the Search API server settings.
  • Enable “Skip item access checks” in the “Query settings” of the search view. (Caution: This is a security risk! When doing this, make sure the rest of your search is configured in a way that will still prevent items with restricted access to be displayed to unauthorized users!)
  • The view needs to be using “Fields” as its row style (“Show:” setting).
  • For all fields, make sure that both “Use entity field rendering” (where available) and “Link this field to its item” are disabled.
  • Also, make sure those fields are actually indexed, so Solr is able to return them. This is simplest done by only adding fields that have “(indexed field)” appended to their names in Views.
  • Using either the “Item language” or “Operations links” fields (“Index [INDEX NAME]” group) will also lead to entity loads.

Of course, you also have to index the fields you’re using in a way that makes sense to display them. For instance, when you use the “HTML filter” processor on a field you display, the field won’t contain any HTML (which might be desired).

To maintain the HTML, see Storing and displaying rendered HTML and #2874641: Select Text Format in Views Field for textual content with values from search index.

Finally, make sure there are actually no entity loads by either using XDebug and setting a break point at some point in the entity loading process, or add some debugging statement to that code. (The first is preferred, as you can then easily tell where the entity load originated and, hence, what still needs to be adapted.)

Help improve this page

Page status: No known problems

You can: