Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Oct 14, 2014 @ 13:36
    Claushingebjerg
    0

    preview from archetype

    I'm building a site using archetype and EZSearch.

    EZsearch, searches the pages correctly, but the preview from the archetype outputs:

    <p>Archetype.Models.ArchetypeModel</p>

    Do you have a solution to get the preview rendered correctly?

    There's a similar post on the matter on the archetype forum here: 
    http://our.umbraco.org/projects/backoffice-extensions/archetype/sound-off!/55402-ezSearch-and-Archetype-result-rendering

    Please help, as getting sites using archetype searchable with your great search package must be a pretty important issue for a lot of people.

     

     

     

     

     

  • Andreas Pfanner 196 posts 314 karma points
    Oct 15, 2014 @ 14:48
    Andreas Pfanner
    0

    Hi,

    I've just built a site based on Tom Fultons great Archetype page builder article:

    http://blog.imulus.com/tom-fulton/building-inline-complex-content-in-umbraco-with-archetype

    So on my document type I have a Field "mainContent" and "sideContent" which have an Archetype with multiple fieldsets (RTE, table, image gallery etc).

    Today I had the same problem with ezSearch preview. I thought that it would be cool to use the same PageBuilder logic (views) there to render the nested content. So I use the same code as in my PageBuilder view for the ezSearch macro (RenderContentResult):

    @foreach (var field in model.PreviewFields.Where(field => result.HasValue(field)))
        {
            Archetype.Models.ArchetypeModel archeModel = result.GetPropertyValue(field) as Archetype.Models.ArchetypeModel;
    
            if (archeModel != null)
            {
                foreach (var pageBuilderFs in archeModel)
                {
                    var partial = "~/Views/Partials/PageBuilder/" + pageBuilderFs.Alias + ".cshtml";
    
                    if (System.IO.File.Exists(Server.MapPath(partial)))
                    {
                        if (!pageBuilderFs.Disabled)
                        {
                        <p>@Highlight(Truncate(Umbraco.StripHtml(Html.Partial(partial, null, new ViewDataDictionary() { { "fieldset", pageBuilderFs } })), model.PreviewLength), model.SearchTerms)</p>
                        }
                    }
                    break;
                }
            }
            else
            {
            <p>@Highlight(Truncate(Umbraco.StripHtml(result.GetPropertyValue(field).ToString()), model.PreviewLength), model.SearchTerms)</p>
            }
            break;
        }
    

    So first of all I check if the current field is an archetype. If so, I loop through the fieldsets and render the desired sub control.

    Hope that helps.

    Best Regards Andreas

  • Claushingebjerg 939 posts 2574 karma points
    Oct 15, 2014 @ 15:12
    Claushingebjerg
    0

    Its getting there :)

    Your code gets me preview from the first archetype block in the stack, but not from the following ones.

    So.If i have the word that is searched for in an RTE in the second archetype block, it finds the page correctly, but renders preview content from the first archetype block on the page.

    Does my explaination makes sense?

     

     

  • Andreas Pfanner 196 posts 314 karma points
    Oct 15, 2014 @ 15:45
    Andreas Pfanner
    0

    Hi,

    yes, I also figured that out. To be honest, I didn't search for a solution for that yet, since its not critical for the particular site, and its okay to have at least anything in the preview (for now).

    I guess the correct solution would be to loop through the fieldsets and find for a match within the rendered content and only break on the first match (not the first fieldset at all), right?

    Best Regards Andreas

  • Matthew Kirschner 323 posts 611 karma points
    Feb 11, 2015 @ 20:20
    Matthew Kirschner
    0

    Hi, all.

    I haven't really found any more recent info on getting ezSearch to work well with Archetype. The code snippet posted by Andres is the closest to what I'm trying to achieve, but simply displaying the first fieldsset in the Archetype was not good for my needs.

    I've made some edits to Andreas code below that attempts to resolve this:

    @helper GetResultsFromArchetype(SearchViewModel model, IPublishedContent result)
    {
        foreach (var field in model.PreviewFields.Where(field => result.HasValue(field)))
        {
            Archetype.Models.ArchetypeModel archeModel = result.GetPropertyValue(field) as Archetype.Models.ArchetypeModel;
    
            if (archeModel != null)
            {
                int maxMatches = 0;
                IHtmlString renderString = null;
                foreach (var pageBuilderFs in archeModel)
                {
                    var partial = "~/Views/Partials/Archetype/" + pageBuilderFs.Alias + ".cshtml";
    
                    if (System.IO.File.Exists(Server.MapPath(partial)))
                    {
                        if (!pageBuilderFs.Disabled)
                        {
                            HtmlString summary = Umbraco.StripHtml(Html.Partial(partial, null, new ViewDataDictionary() { { "fieldset", pageBuilderFs } }));
                            int matches = 0;
                            foreach (var searchTerm in model.SearchTerms)
                            {
                                if (Regex.IsMatch(summary.ToString(), Regex.Escape(searchTerm), RegexOptions.IgnoreCase))
                                {
                                    matches++;
                                }
                            }
                            if (renderString == null || matches > maxMatches)
                            {
                                renderString = Highlight(Truncate(Umbraco.StripHtml(Html.Partial(partial, null, new ViewDataDictionary() { { "fieldset", pageBuilderFs } })), model.PreviewLength), model.SearchTerms);
                                maxMatches = matches;
                            }
                        }
                    }
                }
                <p>@renderString</p>
            }
            else
            {
                <p>@Highlight(Truncate(Umbraco.StripHtml(result.GetPropertyValue(field).ToString()), model.PreviewLength), model.SearchTerms)</p>
            }
            break;
        }
    }
    

    If anyone else has struggled with this as I have, I would love to have some feedback or suggested improvements. My primary issue with the implementation as ezSearch has it is that we're using Truncate to clip out the PreviewLength. This will take the top X amount of text for the preview as opposed to an X amount surrounding the relevant search term(s).

  • Matthew Kirschner 323 posts 611 karma points
    Feb 13, 2015 @ 17:47
    Matthew Kirschner
    0

    I've noticed that the above method works for most cases, but seems to fail in an instance where the page builder contains a Content Picker. The content I'm picking also has an archetype with some member pickers in it. exSearch will not find anything in these nodes.

Please Sign in or register to post replies

Write your reply to:

Draft