Introduction to search lenses

What is a search lens?

A search lens changes what people can find in search based on where they are on your site and which search interface they are using.

Use lenses when different parts of your site need different search behavior. For example, you can show only blog posts in a blog search field, or only products in a store search.

Each lens does two things:

  • decides where it applies
  • decides what content it can return

If you get stuck, contact support and we can help.

Examples

Here are two common setups.

Suppose your blog lives at /blog.

Your header already links to /search, which searches the whole site. Now you want a search input on the blog page that searches only blog content.

To do that, create a new lens from the Search Lenses page.

Screenshot of the Search Lenses overview page with the New lens button highlighted
Create a new lens from the Search Lenses overview.

In the lens editor:

  • Set Paths where this lens should be used to /blog* so the lens applies on the blog and its subpages.
  • Leave Search inputs enabled and turn off Search overlay if you want the blog search block to use this lens, but not the header search link.
  • Turn off products and documents if they should not appear in blog search.
  • In Pages to include or exclude, exclude everything with /*, then bring the blog back with !/blog*.

After you save, the header search still searches the whole site. The blog search field returns blog content only.

Now imagine your site uses language paths in the URL. For example:

  • acme.org and acme.org/en for English
  • acme.org/no for Norwegian
  • acme.org/de for German

You usually want search to return results in the same language the visitor is viewing. Lenses make that possible.

Start with the English version. You can use the Default lens for that and exclude the other language sections:

# Exclude Norwegian pages
/no*

# Exclude German pages
/de*

Then create one lens for Norwegian and one for German. The German example below shows the idea. The Norwegian lens is set up the same way.

Screenshot showing a search lens configured for the German section of a site
A lens that limits search to the German section of a site.

Important settings:

  1. Set Paths where this lens should be used to /de*. Use /de*, not /de, so the lens applies to the full German section and not only the root page.
  2. Enable the search surfaces that should use the German lens. If both Search inputs and Search overlay are enabled, both search experiences stay in German.
  3. In Pages to include or exclude, exclude everything with /*, then bring back German content with !/de*.

After saving, use the lens tester on the Search Lenses overview page to confirm that the right lens is selected for each path.

Screenshot of the lens tester showing the matching lens for a given path
The lens tester shows which lens applies for a given path and search surface.

In this example, testing a Norwegian path highlights the Norwegian lens.