Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Dec 01, 2020 @ 12:00
    Dibs
    0

    Umbraco examine YSOD in search results

    Hi Umbraco Team

    I have simple search page using the following code straight off our Umbraco Examine quick start guide Umbraco Examine quick start guide

    if(ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
                        {
                            var searcher = index.GetSearcher();
                            var results = searcher.CreateQuery("content").Field("nodeName", searchTerm).Execute();
                            if (results.Any())
                            {
                                <ul>
                                    @foreach (var result in results)
                                    {
                                        if (result.Id != null)
                                        {
                                            var node = Umbraco.Content(result.Id);
                                            <li>
                                                <a href="@node.Url">@node.Name</a>
                                            </li>
                                        }
                                    }
                                </ul>
                            }
    

    my view

    foreach (var searchResult in @Model.SearchItems.Skip((page - 1) * Model.PageLimit).Take(Model.PageLimit))
        {
            var searchItem = Umbraco.Content(@searchResult.Id);
            <a href="@searchItem.Url()">
                <h2>@searchItem.Name</h2>
            </a>
            if (@searchItem.HasProperty("contentRTE"))
            {
                @Html.Truncate(@searchItem.Value("contentRTE").ToString(), 250)
            }
        }
    

    I get back results as expected. Issue arises when content editor unpublishes a parent/ancestor node, this leads to a YSOD when the search results contain a published node under the unpublished node.

    Object reference not set to an instance of an object. on line

    var searchItem = Umbraco.Content(@searchResultId);
    

    I'm using Umbraco 8 External Index making use of default standardanalyzer. Im not sure how to handle this error in code, am i missing a method to check if ancestors/parent is published or should Umbraco handle the scenario of a parent/ancestor being unpublished ?

  • Dibs 202 posts 991 karma points
    Dec 07, 2020 @ 08:58
Please Sign in or register to post replies

Write your reply to:

Draft