Copied to clipboard

Flag this post as spam?

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


  • Ryan Noble 17 posts 85 karma points
    Feb 21, 2017 @ 15:18
    Ryan Noble
    0

    Extending Examine to search uTaxonomy fields

    Hi there,

    I was reading on the forums to try add uTaxon's to the examine search and on the one post you touched on extending Examine to resolve the guids, however I'm unable to implement with what I found, is there a way to do this in the current version without resolving prior to it?

    https://our.umbraco.org/projects/backoffice-extensions/utaxonomy/utaxonomy/73879-output-of-guids-list

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Feb 22, 2017 @ 11:43
    Ismail Mayat
    0

    Ryan,

    Whats the issue? You implemented that GatheringNode suggestion in the forum post and that does not work?

    Regards

    Ismail

  • Ryan Noble 17 posts 85 karma points
    Feb 22, 2017 @ 13:35
    Ryan Noble
    0

    Sort of, so I have it firing on the event on index generation but it isnt adding the fields to the index.

    This is what im running in the event handler: if (e.Fields["contentTags"] != null) { var contentTagsJson = e.Fields["contentTags"];

                    var contentTagsIds = JsonConvert.DeserializeObject<List<string>>(contentTagsJson);
                    var contentTagsNames = new List<string>();
    
    
                    // produce a string containing tag names separated by space to make it available for searching and put the string into the new examine field
                    foreach (var id in contentTagsIds)
                    {
                        Taxonomy contentTag = TaxonomyService.GetTaxonomyById("Content Tags", id);
                        contentTagsNames.Add(contentTag.ToString());
                    }
    
                    // for now its possible to search by tag name against "tag_searcheable" examine field 
                    e.Fields["contentTags_searcheable"] = string.Join(" ", contentTagsNames);
                }
    
  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Feb 23, 2017 @ 09:08
    Ismail Mayat
    0

    Ryan,

    Are you able to step through the code i suspect you have an error somewhere? Also check you umbraco logs.

    Regards

    Ismail

  • Ryan Noble 17 posts 85 karma points
    Feb 23, 2017 @ 10:59
    Ryan Noble
    0

    Hi Ishmail,

    So the error is on the "Taxonomy contentTag = TaxonomyService.GetTaxonomyById("Content Tags", id);" line.

    So I tested it and that code with the same ID works when its not in the event handler.

    Object not set to instance of object error.

    So I think the Taxonomy service doesnt exist or cant run for some reason when that event fires

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Feb 24, 2017 @ 08:24
    Ismail Mayat
    0

    Ryan,

    You may need to get taxonomy source code and see if that GetTaxonomyById is using umbraco context under the hood. If it is then that is the issue. During indexing you do not have an umbraco context you have to create one.

    Regards

    Ismail

  • Ryan Noble 17 posts 85 karma points
    Feb 24, 2017 @ 08:59
    Ryan Noble
    0

    Thanks Ismail, That turned out to be the case!

    I've never had to manually create it but we came up with this, I'm not sure if theres a better way to do it

    if (UmbracoContext.Current == null)
            {
                var dummyHttpContext = new HttpContextWrapper(new HttpContext(new SimpleWorkerRequest("/", string.Empty, new StringWriter())));
                UmbracoContext.EnsureContext(
                    dummyHttpContext,
                    ApplicationContext.Current,
                    new WebSecurity(dummyHttpContext, ApplicationContext.Current),
                    UmbracoConfig.For.UmbracoSettings(),
                    UrlProviderResolver.Current.Providers,
                    false);
            }
    
  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Feb 24, 2017 @ 09:14
    Ismail Mayat
    0

    Ryan,

    If that works then all good. Where I have actually needed UmbracoHelper in application started event to pass to gathering node data i have done

    var helper = new UmbracoHelper(UmbracoContext.Current);
    
            indexConfigurator.AttachOnGatheringContentNodeData((sender, e) => ExternalIndexerGatheringNodeData(sender, e, helper));
    

    and the gathering node signature then becomes

     private void ExternalIndexerGatheringNodeData(object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper)
    

    I can then use umbracohelper. That may also work for you?

    Regards

    Ismail

  • Ryan Noble 17 posts 85 karma points
    Mar 03, 2017 @ 12:26
    Ryan Noble
    0

    Thanks Ishmail,

    I'm a bit confused by how you're using the UmbracoHelper to get the context when the context is the thing missing, or did i miss something?

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Mar 03, 2017 @ 13:29
  • Ryan Noble 17 posts 85 karma points
    Mar 03, 2017 @ 13:54
    Ryan Noble
    0

    I just tried that, doesnt resolve the issue so going to stick with the manual context writing.

    Thanks!

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Mar 03, 2017 @ 13:56
    Ismail Mayat
    0

    Ryan,

    what didnt work you dont get umbraco helper in your event? Or I am guessing you need to somehow pass that into utaxonomy?

  • Ryan Noble 17 posts 85 karma points
    Mar 03, 2017 @ 14:19
    Ryan Noble
    0

    So the context needed by the uTaxonomy service isnt there when using the helper, the helper would work when dealing with content and typed content but I'm not certain how this service interacts with the Umbraco context.

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Mar 03, 2017 @ 14:31
    Ismail Mayat
    0

    Ryan,

    Ah ok then that aint going to work. I have as per that blog post used umbraco helper in an event.

    Maybe you can in your event rip out the utaxonony code and use the umbraco helper you give it.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft