Copied to clipboard

Flag this post as spam?

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


  • Mila Pandurska 43 posts 190 karma points
    Feb 01, 2018 @ 20:13
    Mila Pandurska
    0

    I have Node Promo which has a property of type MultiNodeTreePicker and selects which days of week this Promo is valid. I need to perform a search for promos. I have OnExamineGatheringNodeData handler:

    private void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            var content = applicationContext.Services.ContentService.GetPublishedVersion(e.NodeId);
            if (content != null)
            {
                switch (content.ContentType.Alias)
                {
                    case "promo":
                       IEntityService entityService = ApplicationContext.Current.Services.EntityService;
    
                        //dayOfWeek
                        string days = String.Empty;
                      string  featuresAsString = content.Properties["dayOfWeek"].Value != null ? content.Properties["dayOfWeek"].Value.ToString() : "";
                        if (!string.IsNullOrEmpty(featuresAsString))
                        {
                            string[] f = featuresAsString.Split(',');
                            foreach (string item in f)
                            {
                                Udi udiFeature;
                                if (Udi.TryParse(item, out udiFeature))
                                {
                                    var guid = GuidUdi.Parse(udiFeature.ToString());
                                    var response = entityService.GetByKey(guid.Guid);
                                    days = String.Format("{0} {1}", days, response.Id);
                                }
                            }
                        }
                        e.Fields.Add("days", days );
                        break;
                }
            }
    

    This code adds the Ids of "day of week" nodes to my search index and I am able to filter by day of week. The question is how to save the property Title of "day of week" doc. type as well in the search index in order to display it at the result page without making additional request to Umbraco? The web site will have a lot of promos and the search/result should be very fast.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 02, 2018 @ 00:06
    Alex Skrypnyk
    0

    Hi Mila

    If I understood you right, you can do what you with this code:

    e.Fields.Add("days", days);
    e.Fields.Add("title", content.GetValue<string>("title"));
    break;
    

    Then you will be able to get data from index field "title" on the search result page

    /Alex

  • Mila Pandurska 43 posts 190 karma points
    Feb 02, 2018 @ 12:37
    Mila Pandurska
    0

    Hi, Alex, The content variable is of type Promo. I need property Title of "day of week" document type.

Please Sign in or register to post replies

Write your reply to:

Draft