Goal
This article provides information on how to index documents which are above the document size limit.
Prerequisite
Configure Connector - Configure Hawksearch
Setup search service
In order to index documents above the document size limit you need to inherit the HawksearchService class and override the AdaptDocuments. Please refer to the code snippet below.
The following code snippet demonstrates how to strip the document from it’s Content field in order to pass the size limit check.
using System.Collections.Generic; using System.Linq; using Hawksearch.Search; using Telerik.Sitefinity.Services.Search.Data; using Telerik.Sitefinity.Configuration; using Telerik.Sitefinity.Services.Search.Model; using Hawksearch.Configuration; using Hawksearch.SDK.Indexing; using Field = Telerik.Sitefinity.Services.Search.Publishing.Field; namespace Hawksearch122.Custom { public class CustomSearchService : HawksearchService { protected override List<SubmitDocument> AdaptDocuments(IEnumerable<IDocument> documents) { var documentList = new List<IDocument>(); var configManager = ConfigManager.GetManager(); var hawkConfig = configManager.GetSection<HawkSearchConfig>(); foreach (var document in documents) { var documentSize = 0.0; var modifiedDocument = document; foreach (var field in document.Fields) { if (field.Value != null) { documentSize += System.Text.Encoding.Unicode.GetByteCount(field.Value.ToString()) / 1024.0; } } if (documentSize > hawkConfig.DocumentSizeLimit) { modifiedDocument = this.ModifyDocument(document); } documentList.Add(modifiedDocument); } return base.AdaptDocuments(documentList); } private IDocument ModifyDocument(IDocument document) { var fields = new List<IField>(document.Fields); var contentField = document.Fields.FirstOrDefault(f => f.Name == "Content"); fields.Remove(contentField); var modifiedDocument = new Document(fields, document.IdentityField.Name); return modifiedDocument; } } }
Register Custom Search Service
In order to use your custom search service instead of the built-in one you need to register it in the backend.
Open the backend of your Sitefinity instance.
Navigate to Administration → Settings (your-site-domain/Sitefinity/Administration/Settings)
Go to Advanced (your-site-domain/Sitefinity/Administration/Settings/Advanced)
Under Search → Search services → Hawksearch enter the TypeName of you custom search service (e.g. SitefinityWebApp.CustomSearchService)
Save the changes