Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian Milinski 42 posts 165 karma points
    May 11, 2023 @ 18:13
    Brian Milinski
    0

    Simple Site Search Umbraco 10

    Hi, I am wondering how to add searchers in Umbraco 10.

    Currently I am trying to implement a basic site search with the following code:

    @using Umbraco.Cms.Web.Common.PublishedModels;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @using Examine
    @inject IExamineManager ExamineManager
    @{
        Layout = "Master.cshtml";
    }
    
    @{
        var query = Context.Request.Query["q"];
        var canGetSearcher = ExamineManager.TryGetSearcher("ExternalSearcher", out var searcher);
        var count = ExamineManager.RegisteredSearchers.Any();
    
        <p>@count</p>
        if (canGetSearcher)
        {
            <p>here</p>
            var searchResults = searcher.Search(query.ToString());
            if(searchResults.Any())
            {
                <ul>
                    @foreach (var result in searchResults)
                    {
                        if (result.Id != null)
                        {
                            var node = Umbraco.Content(result.Id);
                            <li>
                                <a href="@node.Url()">@node.Name</a>
                            </li>
                        }
                    }
                </ul>
            }
        }
    }
    

    I don't see that I have available "searchers" in the back office. I do see the indexes, of course. How do I add a searcher?

    enter image description here

  • Saicharan Kalyan Reddy Marapareddygari 3 posts 73 karma points
    Oct 09, 2023 @ 16:16
    Saicharan Kalyan Reddy Marapareddygari
    0

    Hi Brian,

    Just wondering if you worked this one out by any chance? I am facing same issue with my Umbraco 10 website and not able to figure out why

    Any kind of help would be really appreciated.

    Thank you in advance

  • Lars Krogh Reinholdt 7 posts 87 karma points
    Oct 10, 2023 @ 07:38
    Lars Krogh Reinholdt
    0

    Hi

    You have to add your seacher to Startup.cs:

    public void ConfigureServices(IServiceCollection services) {
        services.AddUmbraco(_env, _config)
                .AddBackOffice()
                .AddWebsite()
                .AddComposers()
                .Build();
    
        services.AddExamineLuceneMultiSearcher("<seacherName>", new[] { Umbraco.Cms.Core.Constants.UmbracoIndexes.ExternalIndexName, PdfIndexConstants.PdfIndexName });
    

    }

    You should then be able to use the seacher in code:

    if (_examineManager.TryGetSearcher("<seacherName>", out var searcher)) {
    

    ... }

    https://docs.umbraco.com/umbraco-cms/reference/searching/examine/pdfindex-multisearcher

  • Saicharan Kalyan Reddy Marapareddygari 3 posts 73 karma points
    Oct 10, 2023 @ 08:16
    Saicharan Kalyan Reddy Marapareddygari
    0

    Thank you so much Lars for your reply, I am using the same solution like this:

    builder.Services.AddExamineLuceneMultiSearcher("ExternalSearcher", new[] { Constants.UmbracoIndexes.ExternalIndexName });
    

    How ever, doesn't this externalsearcher have to come default? ( just like in umbraco 7 and 8 ). Is there any configuration setting that enables it in Umbraco 10?

  • Lars Krogh Reinholdt 7 posts 87 karma points
    Oct 10, 2023 @ 08:33
    Lars Krogh Reinholdt
    0

    You must register the seacher in startup before you can see it under Examine Management.

            public void ConfigureServices(IServiceCollection services) {
            services.AddUmbraco(_env, _config)
                    .AddBackOffice()
                    .AddWebsite()
                    .AddComposers()
                    .Build();
    
            services.AddExamineLuceneMultiSearcher("<seacherName>", new[] { Umbraco.Cms.Core.Constants.UmbracoIndexes.ExternalIndexName, PdfIndexConstants.PdfIndexName });
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft