Application_Start is too early, Find will not be initialized yet. Better create an InitializableModule for your conventions
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)
{
}
}
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.
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
|
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?
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