Copied to clipboard

Flag this post as spam?

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


  • Gary 73 posts 349 karma points
    Jul 15, 2019 @ 08:16
    Gary
    0

    Fluent API - Following documentation errors

    Hi,

    I am trying to get some search functionality working on a website and i was wondering why i am getting the below issue when following the documentation here:

    enter image description here

    My code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Examine.LuceneEngine.SearchCriteria;
    @{
        var query = "campaigns";
        var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
    
        var searchCriteria = searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
        var searchQuery = searchCriteria.Field("nodeName", query.Boost(5)).Or().Field("nodeName", query.Fuzzy()).And().OrderByDescending("createDate");
        var searchResults = searcher.Search(searchQuery.Compile());
        if (searchResults.Any())
        {
            <ul>
                @foreach (var result in searchResults)
                {
                    <li>
                        <a href="@result.Url">@result.Name</a>
                    </li>
                }
            </ul>
        }
    }
    

    Thank you :)

  • David Challener 79 posts 339 karma points c-trib
    Jul 15, 2019 @ 15:07
    David Challener
    100

    Hi Gary,

    That documentation looks to need a small tweak. To access the Url and Name attributes I'm guessing it's expecting to loop through an IEnumerable of IPublishedContent, so try changing to the following.

    @foreach (var result in Umbraco.TypedContent(searchResults.Select(x=>x.Id)))
    

    HTH, David

  • Gary 73 posts 349 karma points
    Jul 23, 2019 @ 08:18
    Gary
    0

    Thank you David :)

Please Sign in or register to post replies

Write your reply to:

Draft