private void GatheringNodeData(IndexingNodeDataEventArgs nodeData, ApplicationContext context,
                                       UmbracoHelper helper)
        {
            try
            {
                if (nodeData.IndexType.Equals("media", StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }
                if (nodeData.Fields == null)
                {
                    return;
                }

                var pageId = nodeData.NodeId;

                var typedPage = new Products(helper.TypedContent(pageId));

                if (typedPage.HasValue("featuredProducts"))
                {
                    //This is null after line executes
                    var featuredProducts = typedPage.FeaturedProducts;
                    //Yet this works
                    foreach (var featuredProduct in typedPage.GetPropertyValue <Udi[]>("featuredProducts"))
                    {
                        var typedCategory = new Product(helper.TypedContent(featuredProduct as GuidUdi));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(GetType(), $"Error indexing - [{nodeData.NodeId}]", ex);
            }
        }
Beispiel #2
0
        private void AddGroups(IndexingNodeDataEventArgs e, IMember member)
        {
            var groups = Roles.GetRolesForUser(member.Username);

            e.Fields.Add(Constants.Members.Groups, groups.Aggregate("", (list, group) => string.IsNullOrEmpty(list) ? group : $"{list}, {group}"));
            e.Fields.Add($"_{Constants.Members.Groups}", groups.Aggregate("", (list, group) => string.IsNullOrEmpty(list) ? group : $"{list}, {group}"));
        }
Beispiel #3
0
        void indexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            //try
            //{
            //    if (e.Fields["nodeTypeAlias"] == "Project")
            //    {
            //        var projectsProvider = (IListingProvider)MarketplaceProviderManager.Providers["ListingProvider"];
            //        var project = projectsProvider.GetListing(e.NodeId, true);

            //        if (project != null)
            //        {
            //            // add downloads
            //            e.Fields["downloads"] = project.Downloads.ToString();

            //            // add karma
            //            e.Fields["karma"] = project.Karma.ToString();

            //            // add unique id (needed by repo)
            //            e.Fields["uniqueId"] = project.ProjectGuid.ToString();

            //            // add category
            //            e.Fields["categoryId"] = project.CategoryId.ToString();
            //            e.Fields["category"] = Marketplace.library.GetCategoryName(project.Id);

            //            Log.Add(LogTypes.Debug, e.NodeId, "Done adding karma/download data to project index");
            //        }

            //    }
            //}
            //catch (Exception ee)
            //{
            //    Log.Add(LogTypes.Debug, e.NodeId, string.Format("Error adding data to project index: {0}", ee));
            //}
        }
        /// <summary>
        /// Override this method to strip all html from all user fields before raising the event, then after the event
        /// ensure our special Path field is added to the collection
        /// </summary>
        /// <param name="e"></param>
        protected override void OnGatheringNodeData(IndexingNodeDataEventArgs e)
        {
            //strip html of all users fields
            // Get all user data that we want to index and store into a dictionary
            foreach (var field in IndexerData.UserFields)
            {
                if (e.Fields.ContainsKey(field.Name))
                {
                    e.Fields[field.Name] = DataService.ContentService.StripHtml(e.Fields[field.Name]);
                }
            }

            base.OnGatheringNodeData(e);

            //ensure the special path and node type alis fields is added to the dictionary to be saved to file
            var path = e.Node.Attribute("path").Value;

            if (!e.Fields.ContainsKey(IndexPathFieldName))
            {
                e.Fields.Add(IndexPathFieldName, path);
            }

            //this needs to support both schemas so get the nodeTypeAlias if it exists, otherwise the name
            var nodeTypeAlias = e.Node.Attribute("nodeTypeAlias") == null ? e.Node.Name.LocalName : e.Node.Attribute("nodeTypeAlias").Value;

            if (!e.Fields.ContainsKey(NodeTypeAliasFieldName))
            {
                e.Fields.Add(NodeTypeAliasFieldName, nodeTypeAlias);
            }
        }
Beispiel #5
0
 void provider_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
 {
     if (e.IndexType == IndexTypes.Member)
     {
         EnsureMembeshipFlags(e, ApplicationContext.Current.Services.MemberService.GetById(e.NodeId));
     }
 }
Beispiel #6
0
        /// <summary>
        /// Indexes all wysiwyg blocks in the page containers
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SetBuilderWysiwygField(object sender, IndexingNodeDataEventArgs e)
        {
            //get the current node id
            int nodeId;

            if (!int.TryParse(e.Fields["id"], out nodeId))
            {
                return;
            }

            string wysiwyg = "";

            var containerProvider = new ContainerProvider(nodeId);

            foreach (Container container in containerProvider.Containers)
            {
                string containerContent = String.Join(" ",
                                                      container.Blocks.Where(b => b is WysiwygBlock)
                                                      .Cast <WysiwygBlock>()
                                                      .Select(b => b.Content));

                e.Fields.Add("WBContainer_" + container.Name, containerContent);
                wysiwyg += " " + containerContent;
            }
            SetWBWysiwig(e, "WBWysiwyg", DecodeString(wysiwyg));
        }
Beispiel #7
0
        private void ExternalIndexer_GatherContentData(object sender, IndexingNodeDataEventArgs indexingNodeDataEventArgs)
        {
            EnsureUmbracoContext();

            var content = this._umbracoHelper.TypedContent(indexingNodeDataEventArgs.NodeId);

            if (content != null)
            {
                foreach (var lang in ApplicationContext.Current.Services.LocalizationService.GetAllLanguages())
                {
                    try
                    {
                        var searhContentBuilder = new StringBuilder();
                        content.ExtractForExamine(searhContentBuilder, lang.CultureInfo.Name);

                        // Index all properties per language. For Vorto this means the properties for that language.
                        indexingNodeDataEventArgs.Fields.Add("PageContent" + "-" + lang.CultureInfo.Name, searhContentBuilder.ToString());
                    }
                    catch (Exception e)
                    {
                        LogHelper.Warn(this.GetType(), $"NLAPP: Language ({lang.CultureName}) not found on local OS. Use CultureRegionFeeder to add missing culture.");
                        throw new CultureNotFoundException("Culture not found on local OS. Use CultureRegionFeeder to add missing culture.", e);
                    }
                }
            }
        }
        /// <summary>
        /// Add the special __key and _searchEmail fields
        /// </summary>
        /// <param name="e"></param>
        protected override void OnGatheringNodeData(IndexingNodeDataEventArgs e)
        {
            base.OnGatheringNodeData(e);

            if (e.Node.Attribute("key") != null)
            {
                if (e.Fields.ContainsKey(NodeKeyFieldName) == false)
                {
                    e.Fields.Add(NodeKeyFieldName, e.Node.Attribute("key").Value);
                }
            }

            if (e.Node.Attribute("email") != null)
            {
                //NOTE: the single underscore = it's not a 'special' field which means it will be indexed normally
                if (e.Fields.ContainsKey("_searchEmail") == false)
                {
                    e.Fields.Add("_searchEmail", e.Node.Attribute("email").Value.Replace(".", " ").Replace("@", " "));
                }
            }

            if (e.Fields.ContainsKey(IconFieldName) == false)
            {
                e.Fields.Add(IconFieldName, (string)e.Node.Attribute("icon"));
            }
        }
        /// <summary>
        /// Adds custom fields to internal index.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void UmbracoExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            if (e.Fields["nodeTypeAlias"] == "uBlogsyPost")
            {
                // add path
                e.Fields.Add(uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchablePath, e.Fields["path"].Replace(",", " "));

                // get value
                var date = ExamineIndexHelper.GetValueFromFieldOrProperty(e, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableMonth, "uBlogsyPostDate");


                // year
                e.Fields.Add(uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableYear, DateTime.Parse(date).Year.ToString());

                // month
                e.Fields.Add(uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableMonth, DateTime.Parse(date).Month.ToString());

                // day
                e.Fields.Add(uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableDay, DateTime.Parse(date).Day.ToString());


                // label
                ExamineIndexHelper.AddIndexByPropertyInSelectedNodes(e, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableLabels, "uBlogsyPostLabels", "uBlogsyLabelName");
                ExamineIndexHelper.AddIdsFromCsvProperty(e, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableLabelIds, "uBlogsyPostLabels");

                // author name
                ExamineIndexHelper.AddIndexByPropertyInSelectedNodes(e, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableAuthor, "uBlogsyPostAuthor", "uBlogsyAuthorName");
                ExamineIndexHelper.AddIdsFromCsvProperty(e, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableAuthorIds, "uBlogsyPostAuthor");

                // tags
                ExamineIndexHelper.AddIndexByPropertyInSelectedNodes(e, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableTags, "uBlogsyPostTags", "uTagsyTagName");
                ExamineIndexHelper.AddIdsFromCsvProperty(e, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableTagIds, "uBlogsyPostTags");
            }
        }
        private void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            // Create searchable path
            if (e.Fields.ContainsKey("path"))
            {
                e.Fields["searchPath"] = e.Fields["path"].Replace(',', ' ');
            }

            // Lowercase all the fields for case insensitive searching
            var keys = e.Fields.Keys.ToList();

            foreach (var key in keys)
            {
                e.Fields[key] = HttpUtility.HtmlDecode(e.Fields[key].ToLower(CultureInfo.InvariantCulture));
            }

            // Extract the filename from media items
            if (e.Fields.ContainsKey("umbracoFile"))
            {
                e.Fields["umbracoFileName"] = Path.GetFileName(e.Fields["umbracoFile"]);
            }

            // Stuff all the fields into a single field for easier searching
            var combinedFields = new StringBuilder();

            foreach (var keyValuePair in e.Fields)
            {
                combinedFields.AppendLine(keyValuePair.Value);
            }
            e.Fields.Add("contents", combinedFields.ToString());
        }
Beispiel #11
0
        private void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            try
            {
                //string nodeTypeAlias = e.Fields["nodeTypeAlias"];

                //LogHelper.Info<ExamineIndexer>("Gathering node data for node #" + e.NodeId + " (type: " + nodeTypeAlias + ")");

                //if (nodeTypeAlias == "Home" || nodeTypeAlias == "LandingPage" || nodeTypeAlias == "TextPage" || nodeTypeAlias == "BlogPost")
                {
                    string value;

                    if (e.Fields.TryGetValue("grid", out value))
                    {
                        LogHelper.Info <ExamineIndexer>("Node has \"grid\" value\"");
                        e.Fields["grid"] = Meta.GetGridText(e.Fields["grid"]);
                    }
                    else
                    {
                        LogHelper.Info <ExamineIndexer>("Node has no \"grid\" value\"");
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <ExamineIndexer>("MAYDAY! MAYDAY! MAYDAY!", ex);
            }
        }
Beispiel #12
0
        /// <summary>
        /// This checks if any user data might be xml/html, if so we will duplicate the field and store the raw value
        /// so we can retreive the raw value when required.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// This is regarding this issue: http://issues.umbraco.org/issue/U4-644
        /// The underlying UmbracoContentIndexer strips the HTML values before this event is even fired
        /// so we need to check in the underlying 'node' document for the value.
        /// </remarks>
        static void ContentIndexerGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            var indexer = sender as UmbracoContentIndexer;

            if (indexer == null)
            {
                return;
            }

            //loop through each field that is defined as a UserField for the index
            foreach (var field in indexer.IndexerData.UserFields)
            {
                if (e.Fields.ContainsKey(field.Name))
                {
                    //get the original value from the node
                    var node = e.Node.Descendants(field.Name).FirstOrDefault();
                    if (node == null)
                    {
                        continue;
                    }

                    //check if the node value has html
                    if (XmlHelper.CouldItBeXml(node.Value))
                    {
                        //First save the raw value to a raw field, we will change the policy of this field by detecting the prefix later
                        e.Fields[RawFieldPrefix + field.Name] = node.Value;
                    }
                }
            }
        }
Beispiel #13
0
 /// <summary>
 /// Raises the <see cref="E:GatheringNodeData"/> event.
 /// </summary>
 /// <param name="e">The <see cref="Examine.IndexingNodeDataEventArgs"/> instance containing the event data.</param>
 protected virtual void OnGatheringNodeData(IndexingNodeDataEventArgs e)
 {
     if (GatheringNodeData != null)
     {
         GatheringNodeData(this, e);
     }
 }
        /// <summary>
        /// get ultimate picker field acutal value not the id of target
        /// </summary>
        /// <param name="e"></param>
        /// <param name="propertyValue"></param>
        /// <param name="luceneFieldAlias"></param>
        /// <returns></returns>
        private string GetFieldValue(IndexingNodeDataEventArgs e, string propertyValue, string luceneFieldAlias)
        {
            int nodeId = 0;

            int.TryParse(propertyValue, out nodeId);

            var n = new Node(nodeId);

            //node does not exist but we have numeric value
            if (n.Id != 0)
            {
                if (n.GetProperty(luceneFieldAlias) != null)
                {
                    //have to pad out to get lucene range queries to work
                    int i = 0;

                    int.TryParse(n.Name, out i);

                    return(i.ToString("D6"));
                }
                return(n.Name);
            }

            return(nodeId.ToString("D6"));
        }
        private void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            try {
                string nodeTypeAlias = e.Fields["nodeTypeAlias"];

                if (nodeTypeAlias == "Home" || nodeTypeAlias == "LandingPage" || nodeTypeAlias == "TextPage" || nodeTypeAlias == "BlogPost")
                {
                    string value;

                    // Just return now if the "content" field wasn't found
                    if (!e.Fields.TryGetValue("content", out value))
                    {
                        return;
                    }

                    // Parse the raw JSON into an instance of "GridDataModel"
                    GridDataModel grid = GridDataModel.Deserialize(e.Fields["content"]);

                    // Get the searchable text (based on each control in the grid model)
                    e.Fields["content"] = grid.GetSearchableText();
                }
            } catch (Exception ex) {
                // Remember to change the message added to the log. My colleagues typically doesn't,
                // so I occasionally see "MAYDAY! MAYDAY! MAYDAY!" in our logs :(
                LogHelper.Error <SkriftGridExamineIndexer>("MAYDAY! MAYDAY! MAYDAY!", ex);
            }
        }
Beispiel #16
0
 /// <summary>
 /// Called when a node is ignored by the ValidateDocument method.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnIgnoringNode(IndexingNodeDataEventArgs e)
 {
     if (IgnoringNode != null)
     {
         IgnoringNode(this, e);
     }
 }
Beispiel #17
0
        /// <summary>
        /// munge into one field
        /// </summary>
        /// <param name="e"></param>
        private void InjectGroups(IndexingNodeDataEventArgs e)
        {
            var node = new umbraco.NodeFactory.Node(e.NodeId);

            // Umbraco.Core.Logging.LogHelper.Info(this.GetType(), string.Format("test {0}", e.NodeId));



            try
            {
                //umbraco.cms.businesslogic.web.Access.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value);
                if (umbraco.cms.businesslogic.web.Access.IsProtected(e.NodeId, node.Path))
                {
                    var groups = Access.GetAccessingMembershipRoles(node.Id, node.Path);

                    //  Umbraco.Core.Logging.LogHelper.Info(this.GetType(), string.Format("test in the succes if"));

                    e.Fields.Add("GroupAccess", String.Join(",", groups));
                    e.Fields.Add("IsPublic", "false");
                }

                else
                {
                    //    Umbraco.Core.Logging.LogHelper.Info(this.GetType(), string.Format("test in the succes else"));


                    e.Fields.Add("GroupAccess", "0");
                    e.Fields.Add("IsPublic", "true");
                }
            }
            catch (Exception ex)
            {
                Umbraco.Core.Logging.LogHelper.Info(this.GetType(), string.Format("test {0}", ex.ToString()));
            }
        }
Beispiel #18
0
        protected override Dictionary <string, string> GetDataToIndex(XElement node, string type)
        {
            var values = new Dictionary <string, string>();
            var nodeId = int.Parse(node.Attribute("id").Value);

            foreach (var field in node.Attributes())
            {
                string val  = node.SelectExaminePropertyValue(field.Name.LocalName);
                var    args = new IndexingFieldDataEventArgs(node, field.Name.LocalName, val, true, nodeId);
                OnGatheringFieldData(args);
                val = args.FieldValue;

                //don't add if the value is empty/null
                if (!string.IsNullOrEmpty(val))
                {
                    if (values.ContainsKey(field.Name.LocalName))
                    {
                        OnDuplicateFieldWarning(-1, IndexSetName, field.Name.LocalName);
                    }
                    else
                    {
                        values.Add(field.Name.LocalName, val);
                    }
                }
            }

            //raise the event and assign the value to the returned data from the event
            var indexingNodeDataArgs = new IndexingNodeDataEventArgs(node, nodeId, values, type);

            OnGatheringNodeData(indexingNodeDataArgs);
            values = indexingNodeDataArgs.Fields;

            return(values);
        }
        void provider_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            if (e.IndexType == IndexTypes.Content)
            {
                var node = ApplicationContext.Current.Services.ContentService.GetById(e.NodeId);
                InjectTagsWithoutComma(e, node);
                ExtractAuthorData(e, node);
                AggregateFields(e, node, "_title", new[] {
                    "pageTitle",
                    "subTitle"
                });

                AggregateFields(e, node, "_content", new[] {
                    "bodyContent",
                    "detail",
                    "extract",
                    "description",
                    "introduction",
                    "quote",
                    "heading",
                    "body",
                });
            }
            else if (e.IndexType == IndexTypes.Media)
            {
                var node = ApplicationContext.Current.Services.MediaService.GetById(e.NodeId);
                InjectTagsWithoutComma(e, node);
            }
        }
Beispiel #20
0
 private void ExternalIndexerEventHandler_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
 {
     if (e.Fields.ContainsKey("path"))
     {
         e.Fields["searchPath"] = e.Fields["path"].Replace(",", " ");
     }
 }
Beispiel #21
0
        private void ExternalIndexerGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            if (e.IndexType == IndexTypes.Content)  //Content/ Media / Member
            {
                try
                {
                    var fields         = e.Fields;
                    var combinedFields = new StringBuilder();
                    foreach (var keyValuePairs in fields)
                    {
                        combinedFields.AppendLine(keyValuePairs.Value);
                    }

                    e.Fields.Add("contents", combinedFields.ToString());

                    string nodePathField = e.Fields["path"];

                    e.Fields.Add("searchablePath", e.Fields["path"].Replace(",", " ")); //replace the comma with the space to get a tokenized field that is searchable
                }
                catch (Exception exception)
                {
                    LogHelper.Error <Exception>("error " + e.NodeId, exception);
                    throw;
                }
            }
        }
        private void internalIndexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            // Make the path searchable
            string path;

            e.Fields.TryGetValue("path", out path);
            e.Fields.Add("sky_path", (path + "").Replace(',', ' '));
        }
Beispiel #23
0
        private void WebsiteIndexer_OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            //if (e.Fields.ContainsKey("relatedBlogArticles"))
            //{
            //    e.Fields["_relatedBlogArticles"] = e.Fields["relatedBlogArticles"].Replace(',', ' ');
            //}

            InjectGroups(e);
        }
Beispiel #24
0
 private void SetWBWysiwig(IndexingNodeDataEventArgs e, string key, string wysiwyg)
 {
     if (e.Fields.ContainsKey(key))
     {
         e.Fields[key] = wysiwyg;
         return;
     }
     e.Fields.Add(key, wysiwyg);
 }
Beispiel #25
0
        /// <summary>
        /// Make csv-field searchable
        /// </summary>
        /// <param name="e"></param>
        /// <param name="fieldname"></param>
        private void MakeSearchable(IndexingNodeDataEventArgs e, string fieldname)
        {
            string value;

            if (e.Fields.TryGetValue(fieldname, out value))
            {
                e.Fields[fieldname + "_search"] = value.Replace(",", " ");
            }
        }
        /// <summary>
        /// Override this method to strip all html from all user fields before raising the event, then after the event
        /// ensure our special Path field is added to the collection
        /// </summary>
        /// <param name="e"></param>

        protected override void OnGatheringNodeData(IndexingNodeDataEventArgs e)
        {
            //strip html of all users fields if we detect it has HTML in it.
            //if that is the case, we'll create a duplicate 'raw' copy of it so that we can return
            //the value of the field 'as-is'.
            // Get all user data that we want to index and store into a dictionary
            foreach (var field in IndexerData.UserFields)
            {
                string fieldVal;
                if (e.Fields.TryGetValue(field.Name, out fieldVal))
                {
                    //check if the field value has html
                    if (XmlHelper.CouldItBeXml(fieldVal))
                    {
                        //First save the raw value to a raw field, we will change the policy of this field by detecting the prefix later
                        e.Fields[RawFieldPrefix + field.Name] = fieldVal;
                        //now replace the original value with the stripped html
                        e.Fields[field.Name] = DataService.ContentService.StripHtml(fieldVal);
                    }
                }
            }

            base.OnGatheringNodeData(e);

            //ensure the special path and node type alias fields is added to the dictionary to be saved to file
            var path = e.Node.Attribute("path").Value;

            if (e.Fields.ContainsKey(IndexPathFieldName) == false)
            {
                e.Fields.Add(IndexPathFieldName, path);
            }

            //this needs to support both schema's so get the nodeTypeAlias if it exists, otherwise the name
            var nodeTypeAlias = e.Node.Attribute("nodeTypeAlias") == null ? e.Node.Name.LocalName : e.Node.Attribute("nodeTypeAlias").Value;

            if (e.Fields.ContainsKey(NodeTypeAliasFieldName) == false)
            {
                e.Fields.Add(NodeTypeAliasFieldName, nodeTypeAlias);
            }

            //add icon
            var icon = (string)e.Node.Attribute("icon");

            if (e.Fields.ContainsKey(IconFieldName) == false)
            {
                e.Fields.Add(IconFieldName, icon);
            }

            //add guid
            var guid = (string)e.Node.Attribute("key");

            if (e.Fields.ContainsKey(NodeKeyFieldName) == false)
            {
                e.Fields.Add(NodeKeyFieldName, guid);
            }
        }
        private void AddToContentsField(IndexingNodeDataEventArgs e)
        {
            Dictionary <string, string> fields = e.Fields;

            var combinedFields = new StringBuilder();

            foreach (KeyValuePair <string, string> keyValuePair in fields)
            {
                combinedFields.AppendLine(keyValuePair.Value);
            }
            e.Fields.Add("contents", combinedFields.ToString());
        }
        void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            // - allow on Content, Media, Member as it could be relevant to all on them
            var contentService = Umbraco.Core.ApplicationContext.Current.Services.ContentService;

            try
            {
                var document = contentService.GetById(e.NodeId);

                if (document != null)
                {
                    // - process each doc property
                    foreach (Umbraco.Core.Models.PropertyType proptype in document.ContentType.PropertyTypes)
                    {
                        // - Sir Trevor? Go to work!
                        if (proptype.PropertyEditorAlias == propertyEditorKey)
                        {
                            var val = document.GetValue(proptype.Alias);
                            System.Text.StringBuilder combinedtexts = new System.Text.StringBuilder();

                            if (val != null)
                            {
                                try
                                {
                                    dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(e.Fields[proptype.Alias]);
                                    // - object has a data.text property?
                                    if (data != null)
                                    {
                                        for (int i = 0; i < data["data"].Count; i++)
                                        {
                                            var cur = data["data"][i].data;
                                            if (cur != null && cur.Property("text") != null)
                                            {
                                                combinedtexts.Append(cur.Property("text").Value.ToString());
                                            }
                                        }
                                    }

                                    // - just assign combined texts string and let lucene do it's thing ...
                                    e.Fields[proptype.Alias] = combinedtexts.ToString();
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // - nothing for now ...
            }
        }
Beispiel #29
0
 private void provider_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
 {
     if (e.IndexType == IndexTypes.Content)
     {
         var node = ApplicationContext.Current.Services.ContentService.GetById(e.NodeId);
         InjectTagsWithoutComma(e, node);
     }
     else if (e.IndexType == IndexTypes.Media)
     {
         var node = ApplicationContext.Current.Services.MediaService.GetById(e.NodeId);
         InjectTagsWithoutComma(e, node);
     }
 }
Beispiel #30
0
        /// <summary>
        /// Make csv-fields with UDI´s searchable
        /// </summary>
        /// <param name="e"></param>
        /// <param name="fieldname"></param>
        private void MakeSearchableUdi(IndexingNodeDataEventArgs e, string fieldname)
        {
            if (e.Fields.ContainsKey(fieldname))
            {
                string searchFieldname = string.Format("{0}_search", fieldname);
                string fieldnameValue  = e.Fields[fieldname];

                // extract Guids from UDIs
                string searchFieldValue = String.Join(" ", fieldnameValue.Split(',').Select(x => x.Split('/').Last()));

                // add new searchfield
                e.Fields.Add(searchFieldname, searchFieldValue);
            }
        }
Beispiel #31
0
        /// <summary>
        /// The on gathering node data.
        /// </summary>
        /// <param name="e">
        /// The IndexingNodeDataEventArgs.
        /// </param>
        protected override void OnGatheringNodeData(IndexingNodeDataEventArgs e)
        {
            var currentNode = this.nodeFactoryFacade.GetNode(e.NodeId);
            var siteNode = currentNode.FindNodeUpTree("Site");
            if (siteNode != null && siteNode.Id != -1)
            {
                e.Fields.Add("site", siteNode.UrlName);
            }

            var categoriesNode = e.Node.Descendants("categories").SingleOrDefault();
            if (categoriesNode != null)
            {
                e.Fields.Add("categories", ReplaceCommasWithPipes(categoriesNode));
            }
        }