Copied to clipboard

Flag this post as spam?

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


  • Jasper van der Sterren 13 posts 33 karma points
    Aug 31, 2012 @ 10:59
    Jasper van der Sterren
    0

    Examine: how to find out published status

    I'm using an Examine index on Umbraco 4.7.2.

    The index includes unpublished nodes. In my code I would like to know if a certain query result is published or not. However I can't find any field or property on the ExamineResult that contains a published status.

    Any ideas how I can get the published status from Examine results?

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Aug 31, 2012 @ 11:39
    Ismail Mayat
    0

    In the internal index there is field called IsPublished not sure if its in your index. If you have set your examine config to include unpublished then it should be there. Take a look at your index using luke http://code.google.com/p/luke/ if its not there you will need to inject the field in using gatheringnode data event.

    Regards


    Ismail

  • Jasper van der Sterren 13 posts 33 karma points
    Aug 31, 2012 @ 11:58
    Jasper van der Sterren
    0

    I'm actually using the internal index, and there is no IsPublished field...

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Aug 31, 2012 @ 12:22
    Ismail Mayat
    0

    Jasper,

    So you need to do something like below 

    public class ExamineEvents:ApplicationBase

        {

            

            public ExamineEvents()

            {

                ExamineManager.Instance.IndexProviderCollection["InternalIndexer"].GatheringNodeData += InternalExamineEvents_GatheringNodeData;

            }

     

            void InternalExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)

            {

                if (e.IndexType == IndexTypes.Content)

                {

                   //

      Document d= new Document(e.NodeId);

      bool isPublished =false;

      if(d.IsPublished){

    isPublished=true;

      }

      e.Fields.Add("IsPublished",isPublished);

                }

            }

    }

     

    not tested this code just ripped some older code i had and updated so that you can get the IsPublished field into your index.

    Regards

     

    Ismail

     

  • Jasper van der Sterren 13 posts 33 karma points
    Aug 31, 2012 @ 12:58
    Jasper van der Sterren
    0

    Hi Ismail,

    Thanks, that works. Weird that it isn't already a default field.

Please Sign in or register to post replies

Write your reply to:

Draft