How to exclude shortcuts / redirects from the search results in Episerver

Have you set up shortcuts / redirects for some of your pages in Episerver that you are now seeing duplicate results in your site search? One is the correct page and the other is the shortcut page?

There are several approaches to exclude shortcuts / redirects from your search results:

  1. Do not send these pages that are shortcuts to the Episerver Find Index. By doing this, you won’t need to apply any filters when making queries to the Find index.
  2. Send these pages to the Find index, but ensure you apply a filter on your queries to Find to exclude them on the frontend.

I took the first approach because I know that 100% of the searches to Find on the website I’m building this for won’t need to return redirects on the search results. To be frank, I don’t see why you will even need them.

So if you’re approach is the same as mine, which is to use option 1 above, here’s what I had to do to exclude these shortcuts:

  1. Find your Search Initialization Module class (or create one if you don’t have any)
  2. Tell Epi Find to only index pages that have not been set up with shortcuts by adding the below convention:
    ContentIndexer.Instance.Conventions.ForInstancesOf().ShouldIndex(x => x.LinkType == PageShortcutType.Normal);
  3. Clear the contents of your Episerver Find index. This is required to ensure all shortcuts that are already in your index are forced removed.
    1. Navigate to the Episerver Find UI > Configure
    2. Clear index
  4. Run the Episerver Find job. This will now use your new indexing conventions.

Hope this helps anyone.

Discover more from Nicola Ayan

Subscribe now to keep reading and get access to the full archive.

Continue reading