Advertisement
Guest User

Untitled

a guest
Feb 27th, 2013
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace Templates.Search
  2. {
  3.     using EPiServer.Core;
  4.     using EPiServer.Find;
  5.     using EPiServer.Find.ClientConventions;
  6.     using EPiServer.Find.Cms;
  7.     using EPiServer.Find.Cms.Conventions;
  8.     using EPiServer.Find.Cms.Module;
  9.     using EPiServer.Find.UnifiedSearch;
  10.     using EPiServer.Framework;
  11.     using EPiServer.Framework.Initialization;
  12.     using EPiServer.Web.Hosting;
  13.     using System;
  14.     using System.Collections.Generic;
  15.     using NameSpace.To.Your.Extensions;
  16.  
  17.     [InitializableModule]
  18.     [ModuleDependency(typeof(IndexingModule))]
  19.     public class IndexingConventions : IInitializableModule
  20.     {
  21.         private bool eventsAttached;
  22.  
  23.         static readonly IList<string> fileTypesToIndex = new List<string>
  24.         {
  25.             ".txt",
  26.             ".pdf",
  27.             ".doc",
  28.             ".docx",
  29.             ".rtf",
  30.             ".htm",
  31.             ".html",
  32.             ".xls",
  33.             ".xlsx"
  34.         };
  35.  
  36.         public void Initialize(InitializationEngine context)
  37.         {
  38.             if (!eventsAttached)
  39.             {
  40.                 SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<PageData>().PublicSearchFilter(c => c.BuildFilter<PageData>().FilterForVisitor<PageData>());
  41.                 SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<UnifiedFile>().PublicSearchFilter(c => c.BuildFilter<UnifiedFile>().FilterOnUnifiedFileReadAccess());
  42.  
  43.                 FileIndexer.Instance.Conventions.ShouldIndexVPPConvention = new VisibleInFilemanagerVPPIndexingConvention();
  44.                 FileIndexer.Instance.Conventions.ForInstancesOf<UnifiedFile>().ShouldIndex(x => fileTypesToIndex.Contains(x.Extension));
  45.  
  46.                 PageIndexer.Instance.Conventions.EnablePageFilesIndexing();
  47.  
  48.                 SearchClient.Instance.Conventions.ForInstancesOf<UnifiedFile>()
  49.                     .ExcludeField(file => file.Attachment()) // Exclude the default Attachment
  50.                     .IncludeField(file => file.SearchFilename())
  51.                     .IncludeField(file => file.SearchFileExtension())
  52.                     .IncludeField(file => file.SearchHitUrl())
  53.                     .IncludeField(file => file.SearchAttachment()) // Include our extened Attachment
  54.                     .IncludeField(file => file.SearchPublishDate())
  55.                     .IncludeField(file => file.SearchUpdateDate())
  56.                     .IncludeField(file => file.SearchHitTypeName())
  57.                     .IncludeField(file => file.SearchSubsection())
  58.                     .IncludeField(file => file.SearchTitle());
  59.  
  60.         eventsAttached = true;
  61.             }
  62.         }
  63.  
  64.         public void Uninitialize(InitializationEngine context)
  65.         {
  66.             eventsAttached = false;
  67.         }
  68.  
  69.         public void Preload(string[] parameters)
  70.         {
  71.             throw new NotImplementedException();
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement