Mark Stott
Oct 1, 2021
  4289
(2 votes)

Setting Up Search & Navigation in .NET 5.0

UPDATE: The documentation has now been updated and can be found here: https://world.optimizely.com/documentation/developer-guides/search-navigation/getting-started/creating-your-project/

Optimizely CMS for .NET 5.0 is a very exciting thing.  Recently the .NET Core Preview documentation was archived and some of that documentation was merged into the live developer guides. Optimizely have a huge amount of developer documentation and it's going to take a while for this content to be updated for .NET 5.0.  Sadly the current documentation for Optimizely Search and Navigation is still focused on the .NET 4.x world

1. Add the EPiServer.Find.CMS nuget package to your .NET 5.0 solution.

2. Generate a new Search and Navigation index at https://find.episerver.com/

3. Configure the index details in app.config...

When you create the index, you will be shown this snippet to add to your web.config:

<configuration>
    <configSections>
        <section
            name="episerver.find" type="EPiServer.Find.Configuration, EPiServer.Find" requirePermission="false"/>
    </configSections>
    <episerver.find
        serviceUrl="https://demo01.find.episerver.net/RXQGZ5QpXU9cuRSN2181hqA77ZFrUq2e/"
        defaultIndex="yourname_indexname"/>
</configuration> 

You will instead add this to appsettings.json like so:

{
    "EPiServer": {
        "Find": {
            "ServiceUrl": "https://demo01.find.episerver.net/RXQGZ5QpXU9cuRSN2181hqA77ZFrUq2e/",
            "DefaultIndex": "yourname_indexname"
        } 
    } 
}

4. Configure your startup.cs to include the find configuration:

public void ConfigureServices(IServiceCollection services)
{
    services.AddCmsAspNetIdentity<ApplicationUser>();
    services.AddMvc();
    services.AddCms();
    services.AddFind();
 }

You should now have everything you need to write your search queries as normal:

var searchResult = _findClient.Search<SitePageData>()
                              .For(request.SearchText)
                              .UsingSynonyms()
                              .ApplyBestBets()
                              .Skip(skip)
                              .Take(pageSize)
                              .GetContentResult();
Oct 01, 2021

Comments

Scott Reed
Scott Reed Oct 1, 2021 04:41 PM

You can also do it in code (if you so wish) such as if you wanted you local 4th index to be in key vault or something

        public static void SetupSearchAndNavigation(this IServiceCollection services)
        {
            services.Configure<EPiServer.Find.FindOptions>(options =>
            {
                options.DefaultIndex = "INDEX";
                options.ServiceUrl = "URL";
            });

            services.AddCms();
            services.AddFind();
        }

Mark Stott
Mark Stott Oct 3, 2021 04:26 PM

Thank you for the suggestion Scott, it certainly provides alternatives, especially if the client is self hosted like a number of our own clients.  With the DXP platform, none of the index or connection string secrets are actually held anywhere near source code; so I'd expect not to apply this in code but by transforms with empty values again.

Scott Reed
Scott Reed Oct 4, 2021 07:53 AM

Yes that's why I was mentioned the 4th index which is outside of the DXP and usually used for local development or a test server. The startup.cs file as it support querying is local development can give us options for complex configuration options should be need to use them.

Antti Alasvuo
Antti Alasvuo Oct 5, 2021 03:13 PM

For future reference, the configuration of CMS 12+ version and Find, is hidden on this page: https://world.optimizely.com/documentation/developer-guides/search-navigation/getting-started/creating-your-project/ and scroll down to title "Configuring Search & Navigation for the website" (at least at the moment ;)).

Mark Stott
Mark Stott Oct 5, 2021 03:56 PM

Thank you for the update Anttl, at the time of writing that page was still only showing the .NET 4.8 CMS 11 version of the guidance :)

Deepmala S
Deepmala S Mar 9, 2023 10:02 AM

Thanks for this blog, I was finding this solution and it's really helpful and working too properly.

Mark Stott
Mark Stott Mar 9, 2023 11:56 AM

Thank you, I'm glad this has proved helpful after all this time :)

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024