EPiServer CMS Indexing Job: IInitializableModule

Vote:
 

Hi Can someone help me how to use IInitializableModule for conditional Indexing of the connet.

Right now I'm using the following Code in global.asax.cs file to control Indexing of all the pages:

PageIndexer.Instance.Conventions.ForInstancesOf<PageData>().ShouldIndex(x => x.Category.IsIndexableCategoryList());

And the Extension method for Page Data as follows:

public static bool IsIndexableCategoryList(this CategoryList pageCategoryList)
        {
            string categoryName = string.Empty;
            Category IndexCategory = Category.Find("EPiServerFindIndexable");

            if (pageCategoryList.Contains(IndexCategory.ID))
                return true;

            return false;
        }

Is there any way to do the same with IInitializableModule?

Thanks.

#74978
Sep 13, 2013 8:39
Vote:
 

You should be able to use ordinary initializable module infrastructure:

[InitializableModule]
[ModuleDependency(typeof (IndexingModule))]
public class ContentIndexerConfig : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        ContentIndexer.Instance.Conventions.ForInstancesOf<IContent>().ShouldIndex(_ => false);
        ContentIndexer.Instance.Conventions.ForInstancesOf<EditorPage>().ShouldIndex(_ => true);
        ContentIndexer.Instance.Conventions.EnablePageFilesIndexing();

        FileIndexer.Instance.Conventions.ShouldIndexVPPConvention = new VisibleInFilemanagerVPPIndexingConvention();
    }

    public void Uninitialize(InitializationEngine context)
    {
    }

    public void Preload(string[] parameters)
    {
    }
}

    

#74988
Sep 13, 2013 10:24
Vote:
 

I prefer to specify what should be indexed, instead of what should not be indexed. I.e:

ContentIndexer.Instance.Conventions
                .ForInstancesOf<ContentBasePage>()
                .ShouldIndex(x => true);

    

#74989
Sep 13, 2013 10:50
Vote:
 

Hi,

Thanks for the reply.

Sorry I didn't mentioned that I'm using EPiServer CMS 6 R2.

I have used below code :

[InitializableModule]

    [ModuleDependency(typeof(IndexingModule))]
    public class ContentIndexerConfig : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {

            PageIndexer.Instance.Conventions.ForInstancesOf<PageData>().ShouldIndex(x => x.Category.IsIndexableCategoryList());
        }

        public void Uninitialize(InitializationEngine context)
        {

        }

        public void Preload(string[] parameters)
        {

        }
    }
    

And Extension method as :

public static bool IsIndexableCategoryList(this CategoryList pageCategoryList)
        {
            string categoryName = string.Empty;
            Category IndexCategory = Category.Find("EPiServerFindIndexable");

            if (pageCategoryList.Contains(IndexCategory.ID))
                return true;

            return false;
        }

The Code worked just fine for me.

Thanks alot!

 

#75003
Sep 13, 2013 15:32
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.