Copied to clipboard

Flag this post as spam?

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


  • Mac McDell 73 posts 148 karma points
    Jun 02, 2016 @ 18:49
    Mac McDell
    0

    best way to find child content? Author to books example

    Please consider the following: I have book document type . I have author document type. On my book document Type I have a multinode tree picker that is setup to choose the correct author node id.

    This results in a content object that looks like the following:

           <book id="1157" key="61829682-0c8f-40d2-bced-73f5f429622d" parentID="1143" level="4" creatorID="0" sortOrder="0" createDate="2016-04-24T08:55:03" updateDate="2016-05-03T11:19:18" nodeName="2017 BMW M6" urlName="2017-bmw-m6" path="-1,1059,1109,1143,1157" isDoc="" nodeType="1141" creatorName="mac" writerName="Nazhand" writerID="2" template="1140" nodeTypeAlias="book">
    <metaKeywords><![CDATA[some keywords,another set,iyhihu]]></metaKeywords><title><![CDATA[2017 BMW M6]]></title><body><![CDATA[<p><span>some text</span></p>]]></body><thumbnail_tile>1178</thumbnail_tile><images><![CDATA[1178,1179,1181,1180]]></images>
        <author><![CDATA[1246]]></author>
        </book>
    

    When I render my template I convert nodeId 1246 back to content and then present the underlying values. Works great!

    My problem now is that i want to represent all the books the author is attributed to on the 1246 node. Can someone explain how I would go about finding all the books that are now assigned to that author? I am pretty sure this has been asked before but I can't find any reasonable examples. Thanks for any assistance.

  • Brad 69 posts 97 karma points
    Jun 02, 2016 @ 20:39
    Brad
    0

    I use examine. When saving I convert the id list from 1234, 1235 etc to 1234 1235 so lucene can search it. Then it's pretty simple lucene.

    nodeTypeAlias:books authors:1234

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jun 02, 2016 @ 21:15
    Nik
    0

    Brads mechanism would work fairly well. However, I would also look into the relationships api as this is a great use for it.

    If you hook into the save event you can establish a relationship between author and books then simply query the relationship api with the author to get all of the books they are linked to.

  • Mac McDell 73 posts 148 karma points
    Jun 03, 2016 @ 14:55
    Mac McDell
    0

    Hi. I am just looking into the relations API but set up the examine index based on the article Using Examine. I set it up fairly quickly but don't really see how or why your would override the save method.

    Essentially we setup an index on our articles to only index the author userfield (nodeid list). After that it was dead simple to get the IPublishedContent back.

      <IndexSet SetName="BookAuthorIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/BookAuthorSet/">
    <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName" />
      <add Name="updateDate" />
      <add Name="writerName" />
      <add Name="path" />
      <add Name="nodeTypeAlias" />
      <add Name="parentID" />
    </IndexAttributeFields>
    <IndexUserFields>
      <add Name="author"/>
    </IndexUserFields>
    <IncludeNodeTypes>
      <add Name="Book"/>
    </IncludeNodeTypes>
    <ExcludeNodeTypes>
    </ExcludeNodeTypes>
    

    I am just reading up on the relationships API as well but this was a great step. I had no idea lucene was out of the box. Awesome.

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jun 03, 2016 @ 15:23
    Nik
    0

    Hi Mac,

    Pleased to hear you got it working. The reason you may need to hook into the save event is that if any of your properties store information as a comma separated list you need to remove the commas else lucene/examine won't return the correct results.

    It's just something to be aware of.

    Nik

  • Mac McDell 73 posts 148 karma points
    Jun 03, 2016 @ 15:46
    Mac McDell
    0

    Hi Nik. Two questions. 1: Are you saying that if I used the tag editor for example and then setup a tagIndexSearch on that user field the lucene wouldn't work correctly? The tags property produces just a comma separated list currently.

    2: know of any resources that talk about document to document relationships and doing exactly what you are talking about? I see a lot of member to document and they are not doing what we are talking about either. Is the idea behind relationship api that only when documents are created/updated/saved at that point you create that relationship which in turn creates the row entry in the UmbracoRelation table for future lookup?

    I guess we need to look into how our documents are being saved? Would something like this suffice as a starting point? http://www.codeshare.co.uk/blog/intercepting-content-and-member-save-events-in-umbraco/ ? using version 7.4.3 Thanks mac

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jun 03, 2016 @ 15:59
    Nik
    0

    Hi Mac,

    With regards to the tag editor, yes. That is what I'm saying. For some reason (I don't know exactly why) the query engine seems to struggle with ,'s.

    It's a pretty simple fix you have to implement, but you'll need it for any properties that store information in that way.

    This article here: http://shazwazza.com/post/searching-multi-node-tree-picker-data-or-any-collection-with-examine/ gives an example of how to go about resolving the issue but it's only a few lines of code to do the job.

    As for using relationships, you can create a relationship at any point in time I would have thought. However, if I was implementing your requirement I'd look at creating the relationship during the save event. I have to admit, it isn't something I've actually implemented myself but I believe the steps would be something along:

    1) Create a relation type in the developer section 2) hook into the save event 3) using the Relations API, update/create/remove required relation entry.

    I'm afraid I don't know of any resources demonstrating this off of the top of my head. Except for the one I was shown from the Level 2 course I did last year. If you haven't been on any of the Umbraco training I do highly recommend it :-)

    Nik

  • Mac McDell 73 posts 148 karma points
    Jun 03, 2016 @ 16:37
    Mac McDell
    0

    That was my thoughts as well regarding the relationship steps as well. It could be messy however managing that with updates and deletes. As far as training goes.. yes I would love to attend some training unfortunately no training days in North America until December 2016. Thanks for your insights. MM

Please Sign in or register to post replies

Write your reply to:

Draft