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?
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);
}
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.
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);
}
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?
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.
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
Ryan,
Whats the issue? You implemented that GatheringNode suggestion in the forum post and that does not work?
Regards
Ismail
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"];
Ryan,
Are you able to step through the code i suspect you have an error somewhere? Also check you umbraco logs.
Regards
Ismail
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
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
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
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
and the gathering node signature then becomes
I can then use umbracohelper. That may also work for you?
Regards
Ismail
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?
See http://staheri.com/my-blog/2015/march/custom-examine-indexing-using-umbraco-cache/
I just tried that, doesnt resolve the issue so going to stick with the manual context writing.
Thanks!
Ryan,
what didnt work you dont get umbraco helper in your event? Or I am guessing you need to somehow pass that into utaxonomy?
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.
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
is working on a reply...