Copied to clipboard

Flag this post as spam?

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


  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Oct 09, 2013 @ 17:46
    Andy Butland
    0

    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

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 09, 2013 @ 18:31
    Ali Sheikh Taheri
    100

    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

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Oct 10, 2013 @ 10:19
    Andy Butland
    0

    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:

    <scheduledActivities><![CDATA[]]></scheduledActivities>

    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

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Oct 10, 2013 @ 14:39
    Andy Butland
    0

    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();
    

    Thanks again for your help.

    Andy

Please Sign in or register to post replies

Write your reply to:

Draft