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?
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.
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?
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
I'm actually using the internal index, and there is no IsPublished field...
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
Hi Ismail,
Thanks, that works. Weird that it isn't already a default field.
is working on a reply...