Copied to clipboard

Flag this post as spam?

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


  • LesMac 4 posts 24 karma points
    Feb 06, 2016 @ 12:51
    LesMac
    0

    Custom Field Index issue for Rich Text Editor properties

    Hi Guys,

    Having an issue with custom index fields for RTE properties (Other property types seem to be working fine).

    Version : 7.3.6

    Summary of issue: When trying to access RTE properties on OnApplicationStarted appending to the event GatheringNodeData an error is thrown:

    System.NullReferenceException was unhandled by user code
      HResult=-2147467261
      Message=Object reference not set to an instance of an object.
      Source=umbraco
      StackTrace:
           at Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(String text, Boolean preview)
           at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview)
           at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0()
           at System.Lazy`1.CreateValue()
           at System.Lazy`1.LazyInitValue()
           at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__1()
           at System.Lazy`1.CreateValue()
           at System.Lazy`1.LazyInitValue()
           at CreativeJar.Wickes.BrandingPortal.CMS.Handlers.OnApplicationStart.GatheringNodeDataHandler(Object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper) in D:\CodeChronicles\CreativeJar\Branding Portal\Trunk\Code\Wickes.BrandingPortal.CMS\Handlers\OnApplicationStart.cs:line 64
           at CreativeJar.Wickes.BrandingPortal.CMS.Handlers.OnApplicationStart.<>c__DisplayClass2_0.<OnApplicationStarted>b__0(Object sender, IndexingNodeDataEventArgs e) in D:\CodeChronicles\CreativeJar\Branding Portal\Trunk\Code\Wickes.BrandingPortal.CMS\Handlers\OnApplicationStart.cs:line 35
           at Examine.Providers.BaseIndexProvider.OnGatheringNodeData(IndexingNodeDataEventArgs e) in x:\Projects\Examine\Examine\Projects\Examine\Providers\BaseIndexProvider.cs:line 190
           at UmbracoExamine.UmbracoContentIndexer.OnGatheringNodeData(IndexingNodeDataEventArgs e)
           at Examine.LuceneEngine.Providers.LuceneIndexer.GetDataToIndex(XElement node, String type) in x:\Projects\Examine\Examine\Projects\Examine\LuceneEngine\Providers\LuceneIndexer.cs:line 1113
           at Examine.LuceneEngine.Providers.LuceneIndexer.ProcessIndexQueueItem(IndexOperation op, IndexWriter writer) in x:\Projects\Examine\Examine\Projects\Examine\LuceneEngine\Providers\LuceneIndexer.cs:line 1802
           at Examine.LuceneEngine.Providers.LuceneIndexer.ProcessQueueItem(IndexOperation item, ICollection`1 indexedNodes, IndexWriter writer) in x:\Projects\Examine\Examine\Projects\Examine\LuceneEngine\Providers\LuceneIndexer.cs:line 1580
           at Examine.LuceneEngine.Providers.LuceneIndexer.ForceProcessQueueItems(Boolean block) in x:\Projects\Examine\Examine\Projects\Examine\LuceneEngine\Providers\LuceneIndexer.cs:line 1537
      InnerException: 
    

    Hookup Code:

    var helper = new UmbracoHelper(UmbracoContext.Current);
                ExamineManager.Instance.IndexProviderCollection["ContentIndexer"].GatheringNodeData += (sender, e) => GatheringNodeDataHandler(sender, e, helper);
    

    Error is being thrown here:

    foreach (var prop in WidgetProperties.Where(prop => widget.HasProperty(prop) && widget.HasValue(prop)))
                    {
                        content.Append(widget.GetPropertyValue<string>(prop));
                    }
    

    To isolate the issue I tried accessing a RTE property directly with the same results.

    var node = helper.TypedContent(e.NodeId);
    var test = node.GetPropertyValue("pageSummary");
    

    Running HasProperty & Has Value returns true

    Looking in the immediate window, I can see the value when doing GetProperty("pageSummary") however attempting to access this property throws the same exception,

    Unfortunately I am unable to step into the call bur the stack trace seems to indicate that there could be a dependency that is not available at the point of execution.

    Does anyone know if I am attempting to do this at the wrong point of execution?

    I have tried ways to get the raw value (I am not really concerned about actual links parsing etc) however at the moment I have had no luck.

    Many thanks

    Les

  • Graham Starke 2 posts 22 karma points
    Feb 09, 2016 @ 02:42
    Graham Starke
    0

    Hi guys,

    I'm experiencing a similar problem to the one reported by LesMac above, only its for a normal Textstring type.

    Version : 7.3.1

    When I don't have a value saved in that field I'm trying to get the value for it throws the same error as above.

    The only way I could get past this was to specify the default value as an empty string when calling the GetPropertyValue

    var articleTitle = indexingNode.GetPropertyValue<string>(Article.PageTitle, "");
    

    But when doing this it then failed on the documents that DID have a value saved in the field with the same error above.... very strange.

    Thank you, Graham

  • LesMac 4 posts 24 karma points
    Feb 09, 2016 @ 09:43
    LesMac
    0

    This might work?

    if(indexingNode.HasProperty(Article.PageTitle) && indexingNode.HasValue(Article.PageTitle))
    {
           var articleTitle = indexingNode.GetPropertyValue<string>(Article.PageTitle);
           // add it to your index/BL
    }
    
  • LesMac 4 posts 24 karma points
    Feb 09, 2016 @ 09:40
    LesMac
    0

    This seems to have been an issue for some time: (UmbracoContext is not available at the calling method resulting in the error) http://issues.umbraco.org/issue/U4-5953?preventRedirect=true

    Which is a little weird as I am sure I had this working in 7.3.4 (before updating to 7.3.5 then 7.3.6) as the search functionality and indexes were updating.

    It also didn't help that I made the mistake of assuming it was only RTE properties but it seems its all string based ones.

    In the end I found two ways to get the functionality I wanted the first being:

    IContentService cs = ApplicationContext.Current.Services.ContentService;

            var node1 = cs.GetById(e.NodeId);
            var widgets1 = node1.Descendants().Where(x => x.ContentType.Alias.Contains("Widget"));
            var content1 = new StringBuilder();
    
            foreach (var widget in widgets1)
            {
                foreach (var prop in WidgetProperties.Where(prop => widget.HasProperty(prop)))
                {
                    content1.Append(widget.GetValue(prop));
                    content1.Append(" ");
                }
            }
    
            var result = content1.ToString();
    

    The problem with the method above was that it wasn't getting all the descendants just the first level.

    The next solution got the results I was expecting but due to its greedy nature (not found a nice way of only getting the nodes I want) a fair bit slower. As its a small site and only effects the content editors it seems like a necessary evil.

    var node = new Node(e.NodeId);

            var widgets = node.GetDescendantNodes();
    
            var content = new StringBuilder();
            foreach (var widget in widgets)
            {
                foreach (var prop in WidgetProperties.Where(prop => widget.HasProperty(prop)))
                {
                    content.Append(widget.GetProperty(prop));
                    content.Append(" ");
                }
            }
    
            e.Fields.Add("pageContent", content.ToString());
    

    Not sure if the above will help you Grayham :)

  • Graham Starke 2 posts 22 karma points
    Feb 10, 2016 @ 04:46
    Graham Starke
    0

    Hi Les,

    I still couldn't really get to the bottom as to why this exception is being thrown, and to be honest it didn't make a lot of sense because when I use both indexingNode.HasProperty(Article.PageTitle) and indexingNode.HasValue(Article.PageTitle) then both return true but the exception is still being thrown when I try to access the property in the typed content. And this is working for all other properties on the document type.

    The only thing that is different with the property I'm trying to access is that is a property that is being "inherited" from a document type one level before it (like a base page).

    In the end I too had to make use of the Content Service to go and grab the node from the database and then get the property from there which seems to work fine, but obviously much slower.

    If anyone can shed some light on this, then that will be much appreciated.

    Thanks, Graham

Please Sign in or register to post replies

Write your reply to:

Draft