private static void ArborNewsGatheringNodeDataHandler(object sender, IndexingNodeDataEventArgs e)
 {
     if (e.Fields.ContainsKey("arbors") && !String.IsNullOrEmpty(e.Fields["arbors"]))
     {
         e.Fields["arbors"] = e.Fields["arbors"].Replace(",", " ");
     }
 }
        /// <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");
            }
        }
Example #3
0
        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());
        }
 void provider_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
 {
     if (e.IndexType == IndexTypes.Member)
     {
         EnsureMembershipFlags(e, ApplicationContext.Current.Services.MemberService.GetById(e.NodeId));
     }
 }
Example #5
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));
            //}
        }
Example #6
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);
 }
        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 ...
            }
        }
        void ExamineEventsInternal_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            //need to fudge rte field so that we have internal link nodeids in the internal index
            var rteFields = RteFields;

            if (e.IndexType == IndexTypes.Content)
            {
                var d = new Document(e.NodeId);
                foreach (var rteField in rteFields)
                {
                    if (d.getProperty(rteField) != null && d.getProperty(rteField).Value != null)
                    {
                        var rteEncoded = HttpUtility.HtmlEncode(d.getProperty(rteField).Value.ToString().Replace("localLink:", "localLink: ").Replace("}", " } "));
                        e.Fields.Add("rteLink" + rteField, rteEncoded);
                    }
                }

                var treePickerFields = TreePickerFields;
                foreach (var treePickerField in treePickerFields)
                {
                    if (e.Fields.ContainsKey(treePickerField))
                    {
                        var content = e.Fields[treePickerField];

                        // if it's a csv type and there's more than one item,
                        // separate with a space so the nodes are indexed separately
                        if (content.Contains(","))
                        {
                            content = content.Replace(",", " ");
                        }
                        else
                        {
                            // if it's an XML type tree picker, get the xml and transform into a space separated list
                            var node = new Node(e.NodeId);
                            var value = node.GetProperty(treePickerField).Value;

                            if (value.Contains("<MultiNodePicker"))
                            {
                                var dynamicXml = new DynamicXml(value);
                                content = string.Join(" ", dynamicXml.Descendants().Select(de => de.InnerText));
                            }
                        }
                        e.Fields[treePickerField] = content;
                    }
                }

                e.Fields.Add("IsPublished", d.Published.ToString());
            }
        }
        /// <summary>
        /// Need to ensures some custom data is added to this index
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void ProjectIndexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            //Need to add category, which is a parent folder if it has one, we only care about published data
            // so we can just look this up from the published cache

            EnsureUmbracoContext();

            var node = UmbracoContext.Current.ContentCache.GetById(e.NodeId);
            if (node == null) return;

            //this has a project group which is it's category
            if (node.Parent.DocumentTypeAlias == "ProjectGroup")
            {
                e.Fields["categoryFolder"] = node.Parent.Name.ToLowerInvariant().Trim();
            }
        }
        void externalIndexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            //Bruges til at lave custom handlinger til et Examine index. I dette tilfælde "ExternalIndexer"

            //Eksempel: laver LowerCaseIndex af felterne
            var lcifields = e.Fields.Where(a => !a.Key.EndsWith("_lci"));

            Dictionary<string, string> lci = new Dictionary<string, string>();

            foreach (var field in lcifields)
            {
                lci[field.Key + "_lci"] = field.Value.ToLowerInvariant();
            }

            foreach (var field in lci)
                e.Fields[field.Key] = field.Value;

        }
        void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            //Do LCI for search
            var lcifields = e.Fields.Where(a => !a.Key.EndsWith("_lci"));

            Dictionary<string, string> lci = new Dictionary<string, string>();

            foreach (var field in lcifields)
            {
                lci[field.Key + "_lci"] = field.Value.ToLowerInvariant();
            }

            foreach (var field in lci)
            {
                e.Fields[field.Key] = field.Value;
            }

            e.Fields.Add("allitems", "1");
        }
Example #12
0
        static void ExamineEventsHandler_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            var indexer = sender as BaseIndexProvider;

            if (indexer == null)
                return;

            foreach (var examineEventsConsumer in _examineEventsConsumers)
            {
                if (examineEventsConsumer.ApplyOnIndex(indexer.Name))
                    try
                    {
                        examineEventsConsumer.OnGatheringNodeData(e);
                    }
                    catch (Exception exception)
                    {
                        LogHelper.Error<ExamineEventsHandler>("Error With Event Consumer", exception);
                    }
            }
        }
        /// <summary>
        /// Make sure the isApproved and isLockedOut fields are setup properly in the index
        /// </summary>
        /// <param name="e"></param>
        /// <param name="node"></param>
        /// <remarks>
        ///  these fields are not consistently updated in the XML fragment when a member is saved (as they may never get set) so we have to do this.
        ///  </remarks>
        private void EnsureMembershipFlags(IndexingNodeDataEventArgs e, IContentBase node)
        {
            Func<string, bool> valueExists = fieldName => {
                return e.Node.Nodes().Any(n => n is XElement ? (n as XElement).Name == fieldName : false);
            };

            if (!valueExists(Constants.Conventions.Member.IsLockedOut) || !valueExists(Constants.Conventions.Member.IsLockedOut))
            {
                // We need to augment from the database.
                var member = ApplicationContext.Current.Services.MemberService.GetById(e.NodeId);
                if (!e.Fields.ContainsKey(Constants.Conventions.Member.IsLockedOut) && !valueExists(Constants.Conventions.Member.IsLockedOut))
                {
                    e.Fields.Add(Constants.Conventions.Member.IsLockedOut, member.IsLockedOut.ToString().ToLower());
                }
                if (!e.Fields.ContainsKey(Constants.Conventions.Member.IsApproved) && !valueExists(Constants.Conventions.Member.IsApproved))
                {
                    e.Fields.Add(Constants.Conventions.Member.IsApproved, member.IsApproved.ToString().ToLower());
                }
            }
        }
        private static void InternalMemberGatheringNodeDataHandler(object sender, IndexingNodeDataEventArgs e)
        {
            var memberId = e.Fields["id"];
            var member = new Member(Convert.ToInt32(memberId));
            var memberGroups = member.Groups.Values;
            var memberGroupNameList = (from MemberGroup @group in memberGroups select @group.Id).ToList();
            e.Fields.Add("_memberGroups", string.Join(" ", memberGroupNameList));

            var members = MemberService.Members.Where(x => x.UserName == member.LoginName);
            if (members.Any())
            {
                e.Fields.Add("memberFirstName", members.First().FirstName);
                e.Fields.Add("memberLastName", members.First().LastName);
                e.Fields.Add("legacyEmail", members.First().Email);
                e.Fields.Add("hasMultipleData", members.Count() > 1 ? "1" : "0");
            }

            if (e.Fields.ContainsKey("arbors") && !String.IsNullOrEmpty(e.Fields["arbors"]))
            {
                e.Fields["arbors"] = e.Fields["arbors"].Replace(",", " ");
            }
        }
        private void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            // Create searchable path
            if (e.Fields.ContainsKey("path"))
            {
                e.Fields["searchPath"] = e.Fields["path"].Replace(',', ' ');
            }

            // 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());
        }
Example #16
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));
        }
 void memberIndexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
 {
 }
Example #18
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;
                    }
                }
            }

        }
Example #19
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);
 }
Example #20
0
 void memberIndexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
 {
     //Bruges til at lave custom handlinger til et Examine index. I dette tilfælde "InternalMemberIndexer"
 }
Example #21
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);
 }
Example #22
0
        /// <summary>
        /// Used after we have gathered all information on a product/productvariant so we can inject extra fields into the index only
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ProductIndexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            var value = "-1";

            if (e.Fields.ContainsKey("downloadMediaId"))
            {
                int id;
                if (int.TryParse(e.Fields["downloadMediaId"], out id))
                {
                    if (ApplicationContext.Current != null && id > 0)
                    {
                        var mediaItem = ApplicationContext.Current.Services.MediaService.GetById(id);
                        if (mediaItem != null)
                        {
                            value = string.Join(" ", mediaItem.Properties.Select(x => x.Id.ToString(CultureInfo.InvariantCulture)));
                        }
                    }
                }
            }

            e.Fields.Add("downloadMediaPropertyIds", value);
        }
        /// <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("__key") == false)
                    e.Fields.Add("__key", 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("@", " "));
            }
        }
		protected void GatheringNodeDataHandler(object sender, IndexingNodeDataEventArgs e)
		{
			try
			{
				foreach (var xElement in e.Node.Elements().Where(element => element.Name.LocalName.StartsWith("description")))
				{
					if (xElement != null) e.Fields.Add("RTEItem" + xElement.Name.LocalName, xElement.Value);
				}
			}
			catch
			{
			}

			foreach (var field in defaultPriceValues())
			{
				try
				{
					//grab the current data from the Fields collection
					string value;
					if (e.Fields == null || !e.Fields.TryGetValue(field, out value))
						continue;
					var currencyFieldValue = e.Fields[field];

					var currencyValueAsInt = int.Parse(currencyFieldValue);

					//prefix with leading zero's
					currencyFieldValue = currencyValueAsInt.ToString("D8");

					//now put it back into the Fields so we can pretend nothing happened! ;)
					e.Fields[field] = currencyFieldValue;
				}
				catch (Exception ex)
				{
					Domain.Log.Instance.LogError("GatheringNodeDataHandler defaultPriceValues Examine: " + ex);
				}
			}

			foreach (var field in DefaultCsvValues())
			{
				try
				{
					string value;
					if (e.Fields == null || !e.Fields.TryGetValue(field, out value))
						continue;
					var csvFieldValue = e.Fields[field];
					//Log.Instance.LogDebug( "examine MNTP before: " + mntp);
					//let's get rid of those commas!
					csvFieldValue = csvFieldValue.Replace(",", " ");
					//Log.Instance.LogDebug( "examine MNTP after: " + mntp);
					//now put it back into the Fields so we can pretend nothing happened!
					e.Fields[field] = csvFieldValue;
				}
				catch (Exception ex)
				{
					Domain.Log.Instance.LogError("GatheringNodeDataHandler DefaultCsvValues Examine: " + ex);
				}
			}
		}
        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)
            {
                if (e.Fields.ContainsKey(field.Name))
                {
                    //check if the field value has html
                    if (XmlHelper.CouldItBeXml(e.Fields[field.Name]))
                    {
                        //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] = e.Fields[field.Name];
                        //now replace the original value with the stripped html
                        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);
        }
Example #26
0
        /// <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);
        }