Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Templates.Search
- {
- using EPiServer.Core;
- using EPiServer.Find;
- using EPiServer.Find.ClientConventions;
- using EPiServer.Find.Cms;
- using EPiServer.Find.Cms.Conventions;
- using EPiServer.Find.Cms.Module;
- using EPiServer.Find.UnifiedSearch;
- using EPiServer.Framework;
- using EPiServer.Framework.Initialization;
- using EPiServer.Web.Hosting;
- using System;
- using System.Collections.Generic;
- using NameSpace.To.Your.Extensions;
- [InitializableModule]
- [ModuleDependency(typeof(IndexingModule))]
- public class IndexingConventions : IInitializableModule
- {
- private bool eventsAttached;
- static readonly IList<string> fileTypesToIndex = new List<string>
- {
- ".txt",
- ".pdf",
- ".doc",
- ".docx",
- ".rtf",
- ".htm",
- ".html",
- ".xls",
- ".xlsx"
- };
- public void Initialize(InitializationEngine context)
- {
- if (!eventsAttached)
- {
- SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<PageData>().PublicSearchFilter(c => c.BuildFilter<PageData>().FilterForVisitor<PageData>());
- SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<UnifiedFile>().PublicSearchFilter(c => c.BuildFilter<UnifiedFile>().FilterOnUnifiedFileReadAccess());
- FileIndexer.Instance.Conventions.ShouldIndexVPPConvention = new VisibleInFilemanagerVPPIndexingConvention();
- FileIndexer.Instance.Conventions.ForInstancesOf<UnifiedFile>().ShouldIndex(x => fileTypesToIndex.Contains(x.Extension));
- PageIndexer.Instance.Conventions.EnablePageFilesIndexing();
- SearchClient.Instance.Conventions.ForInstancesOf<UnifiedFile>()
- .ExcludeField(file => file.Attachment()) // Exclude the default Attachment
- .IncludeField(file => file.SearchFilename())
- .IncludeField(file => file.SearchFileExtension())
- .IncludeField(file => file.SearchHitUrl())
- .IncludeField(file => file.SearchAttachment()) // Include our extened Attachment
- .IncludeField(file => file.SearchPublishDate())
- .IncludeField(file => file.SearchUpdateDate())
- .IncludeField(file => file.SearchHitTypeName())
- .IncludeField(file => file.SearchSubsection())
- .IncludeField(file => file.SearchTitle());
- eventsAttached = true;
- }
- }
- public void Uninitialize(InitializationEngine context)
- {
- eventsAttached = false;
- }
- public void Preload(string[] parameters)
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement