Add number of times a node is referenced to the Examine index
I have a need to add to an examine index for a node the number of times it has been referenced by nodes of another type via a multi-node picker.
In other words I'm saving and indexing a node of type A. Nodes of type B have a multi-picker that allow you to select nodes of type A. So I want to add a field to the index that has the number of nodes of type B that have a reference to the node being indexed. I then plan to use that to allow search results to be ordered by "most used".
I've tried using umbraco.uQuery.GetNodesByType("TypeB") in the GatheringNodeData event - but this fails with a NullReferenceException - it seems that some uQuery methods aren't available without an Umbraco (or Http?) Context.
That's a great idea and a very nice feature, but it doesn't seem to work for what I'm trying to do unforunately. I've tried to index the new relation links property but it doesn't appear in the Examine index. I've also looked in umbraco.config and can see just:
i.e. empty. Even though it renders OK in the back-office UI. So I guess it's just working out the relations on the fly and displaying them in the back-office rather than actually recording anything that can be picked up in the indexing.
Have managed to get this working. Although the information isn't publised, it is available in the relations API, and hence if I add this to my GatheringNodeData event I can pull the number out and get it into the Examine index:
var relType = RelationType.GetByAlias("myRelation");
var count = Relation.GetRelations(nodeId, relType).Count();
Add number of times a node is referenced to the Examine index
I have a need to add to an examine index for a node the number of times it has been referenced by nodes of another type via a multi-node picker.
In other words I'm saving and indexing a node of type A. Nodes of type B have a multi-picker that allow you to select nodes of type A. So I want to add a field to the index that has the number of nodes of type B that have a reference to the node being indexed. I then plan to use that to allow search results to be ordered by "most used".
I've tried using umbraco.uQuery.GetNodesByType("TypeB") in the GatheringNodeData event - but this fails with a NullReferenceException - it seems that some uQuery methods aren't available without an Umbraco (or Http?) Context.
Anyone have any other ideas how I could do this?
Using 4.11.
Thanks in advance.
Andy
Hi Andy,
you probably can use relation links: (here)
Then on each page you know how many pages are referenced to the current page.
When you are indexing you could simply count it and add it to examine index.
you still need to reindex this page if a reference is added from another page.
Hope that helps
Cheers
Ali
Thanks Ali.
That's a great idea and a very nice feature, but it doesn't seem to work for what I'm trying to do unforunately. I've tried to index the new relation links property but it doesn't appear in the Examine index. I've also looked in umbraco.config and can see just:
i.e. empty. Even though it renders OK in the back-office UI. So I guess it's just working out the relations on the fly and displaying them in the back-office rather than actually recording anything that can be picked up in the indexing.
Andy
Have managed to get this working. Although the information isn't publised, it is available in the relations API, and hence if I add this to my GatheringNodeData event I can pull the number out and get it into the Examine index:
Thanks again for your help.
Andy
is working on a reply...