Unpublished pages being Indexed

Vote:
 

Hi,

How do you prevent pages from being Indexed that haven’t been published?

I have created a page and it instantly Indexes in FIND even though the page isn’t published – this is EPiServer 7.5.

 

I have added this to my Application_Start

 

            ContentIndexer.Instance.Conventions.ForInstancesOf<PageData>().ShouldIndex(x => x.Status == VersionStatus.Published);

            ContentIndexer.Instance.Invisible = false;

 

And it still publishes the page.

 

Any ideas?

 

Jon

#209096
Nov 07, 2019 15:08
Vote:
 

Application_Start is too early, Find will not be initialized yet. Better create an InitializableModule for your conventions

#209101
Nov 07, 2019 15:32
Vote:
 

Jeroen is right, I just tested it and yeah it's working

Thanks to Jeroen...

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Find.Cms.Module.IndexingModule))]
public class SearchConventionInitializationModule : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        ContentIndexer.Instance.Conventions.ForInstancesOf<PageData>().ShouldIndex(x => x.Status == VersionStatus.Published);
    }

    public void Uninitialize(InitializationEngine context)
    {
    }
}
#209102
Nov 07, 2019 15:41
Vote:
 

Yep - just tested it and it works a treat - thank you so much

#209103
Nov 07, 2019 15:43
Vote:
 

Why not rely on FilterForVisitor() instead?

The content not being published, is not the only reason to keep content hidden from a specific visitor. Not indexing content until it's published, does only solve one of them.

#209106
Nov 07, 2019 17:01
Jonathan Roberts - Nov 07, 2019 17:08
Is that available in 7.5?
- Nov 07, 2019 17:15
It's part of Episerver.Find.CMS.
https://world.episerver.com/documentation/class-library/?documentId=find/8/6941FA55
Vote:
 

Since I added that in the code I can no longer Copy and Paste a page in the CMS - I keep getting:

episerver failed to copy page exception: XXXX {page name} content with guid "00000000-0000-0000-0000-000000000000" was not found

 

2019-11-25 08:18:31,110 [488] ERROR EPiServer.Find.Cms.ContentEventIndexer: An exception occured while indexing (IContent): 46409_104428. Content with Guid "00000000-0000-0000-0000-000000000000" was not found.

EPiServer.Core.ContentNotFoundException: Content with Guid "00000000-0000-0000-0000-000000000000" was not found

   at EPiServer.Core.DefaultContentLoader.Get[T](Guid contentGuid, LoaderSettings loaderSettings)

   at EPiServer.Core.DefaultContentLoader.Get[T](Guid contentGuid, ILanguageSelector selector)

   at EPiServer.Core.DefaultContentLoader.Get[T](Guid contentGuid)

   at EPiServer.Core.DefaultContentRepository.Get[T](Guid contentGuid)

   at EPiServer.Find.Cms.ContentExtensions.SiteId(IContent content)

  at EPiServer.Find.DelegateValueProvider`2.GetValue(Object target)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)

   at EPiServer.Find.Api.BulkActionConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)

   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)

   at EPiServer.Find.Json.Serializer.SerializeToStringBuilder(JsonSerializer serializer, Object value, StringBuilder buffer)

   at EPiServer.Find.Api.BulkCommand.Execute()

   at EPiServer.Find.Cms.ContentIndexer.IndexWithRetry(IContent[] contents, Int32 maxRetries)

   at EPiServer.Find.Cms.ContentIndexer.Index(IEnumerable`1 content, IndexOptions options)

   at EPiServer.Find.Cms.ContentEventIndexer.Index(IContent content)

2019-11-25 08:18:31,157 [488] ERROR EPiServer.Core.Transfer.TransferLogger: 10.5.3 Export/import error: Exception: Content with Guid "00000000-0000-0000-0000-000000000000" was not found

EPiServer.Core.ContentNotFoundException: Content with Guid "00000000-0000-0000-0000-000000000000" was not found

   at EPiServer.Core.DefaultContentLoader.Get[T](Guid contentGuid, LoaderSettings loaderSettings)

   at EPiServer.Core.DefaultContentLoader.Get[T](Guid contentGuid, ILanguageSelector selector)

   at EPiServer.Core.DefaultContentLoader.Get[T](Guid contentGuid)

   at EPiServer.Core.DefaultContentRepository.Get[T](Guid contentGuid)

   at EPiServer.Find.Cms.ContentExtensions.SiteId(IContent content)

   at EPiServer.Find.DelegateValueProvider`2.GetValue(Object target)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)

   at EPiServer.Find.Api.BulkActionConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)

   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)

   at EPiServer.Find.Json.Serializer.SerializeToStringBuilder(JsonSerializer serializer, Object value, StringBuilder buffer)

   at EPiServer.Find.Api.BulkCommand.Execute()

   at EPiServer.Find.Cms.ContentIndexer.IndexWithRetry(IContent[] contents, Int32 maxRetries)

   at EPiServer.Find.Cms.ContentIndexer.Index(IEnumerable`1 content, IndexOptions options)

   at EPiServer.Find.Cms.ContentEventIndexer.Index(IContent content)

   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)

   at EPiServer.Core.DefaultContentEvents.RaiseContentEvent(String key, ContentEventArgs eventArgs)

   at EPiServer.Core.DefaultContentRepository.RaisePostSaveEvents(IContent content, SaveContentEventArgs eventArgs, Boolean isNew, Boolean isSave)

   at EPiServer.Core.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)

   at EPiServer.Core.Transfer.ContentTransfer.PreSave(IContent content, AccessLevel requiredDestinationAccess)

   at EPiServer.Core.Transfer.ContentTransfer.Import(RawContent rawContent, AccessLevel requiredDestinationAccess, Guid& importedPageGuid)

   at EPiServer.Core.Transfer.ContentTransfer.Import(ITransferContentData content, AccessLevel requiredDestinationAccess)

   at EPiServer.Enterprise.DataImporter.ImportContents[T](XmlTextReader reader, ZipPackage package)

   at EPiServer.Enterprise.DataImporter.ImportStream(ZipPackage package, XmlTextReader reader, String partName)

   at EPiServer.Enterprise.DataImporter.ImportPartOfPackage(ZipPackage package, String partName)

   at EPiServer.Enterprise.DataImporter.ImportRaw(ZipPackage package)

   at EPiServer.Enterprise.DataImporter.Import()

2019-11-25 08:18:33,263 [488] ERROR EPiServer.Enterprise.Transfer.ContentCopyHandler: Failed to copy pages with root '28826' to '5957'

 

#210783
Edited, Dec 05, 2019 16:06
Vote:
 

Probably because there is no version status yet, when you copy, if I remember correctly. And that is what you added to your conventions. So why not rely on FilterForVisitor() as Tomas said. It's not a problem that it's in the index, but that Find returns them in a search result, I guess?

#210785
Dec 05, 2019 17:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.