/// <inheritDoc /> public void Process(CoveoPostItemProcessingPipelineArgs p_Args) { s_Logger.TraceEntering(); Precondition.NotNull(p_Args, () => () => p_Args); CoveoIndexableItem coveoIndexableItem = p_Args.CoveoItem; SitecoreIndexableItem sitecoreIndexableItem = p_Args.Item as SitecoreIndexableItem; ISearchIndex searchIndex = m_CoveoIndexFetcher.GetCoveoSearchIndex(sitecoreIndexableItem); IFieldNameTranslator translator = searchIndex.FieldNameTranslator as IFieldNameTranslator; bool isFieldRemoverActive = IsFieldRemoverActive(sitecoreIndexableItem); bool isPreviewRemoverActive = IsPreviewRemoverActive(sitecoreIndexableItem); string newUniqueId = coveoIndexableItem.UniqueId + LimitedItemSuffix; string newUri = coveoIndexableItem.Uri + LimitedItemSuffix; byte[] hiddenButSearchableItemPreview = coveoIndexableItem.BinaryData; if (coveoIndexableItem != null && sitecoreIndexableItem != null && (isFieldRemoverActive || isPreviewRemoverActive)) { // Add information in metadata to spot the duplicate and to indicates which fields needs to be stripped Dictionary <string, object> newMetadata = new Dictionary <string, object>(coveoIndexableItem.Metadata); String[] SitecoreFieldsToHide = newMetadata[SITECORE_FIELDS_TO_HIDE_ID_LIST].ToString().Split(CHAR_SEPARATOR_FOR_FIELDS_TO_REMOVE); List <string> fieldsToHideList = new List <string>(); foreach (string field in SitecoreFieldsToHide) { fieldsToHideList.Add(translator.TranslateToCoveoFormat(sitecoreIndexableItem.GetFieldById(new ID(field)).Name)); } ; newMetadata.Add(REMOVED_FIELDS_NAME_METADATA_KEY, string.Join(STRING_SEPARATOR_FOR_FIELDS_TO_REMOVE, fieldsToHideList)); newMetadata.Add(ITEM_IS_A_COPY_METADATA_KEY, CHECKBOX_FIELD_CHECKED_VALUE); CoveoIndexableItem strippedItem = new CoveoIndexableItem { //Modify the ID, the metadata and the URI UniqueId = newUniqueId, Metadata = newMetadata, Uri = newUri, //Add anonymous permissions Permissions = CreateAnonymousAccessRule(), //Copy the rest of the original item data BinaryData = coveoIndexableItem.BinaryData, BinaryDataMimeType = coveoIndexableItem.BinaryDataMimeType, BinaryDataPath = coveoIndexableItem.BinaryDataPath, ClickableUri = coveoIndexableItem.ClickableUri, FileName = coveoIndexableItem.FileName, HasSubItems = coveoIndexableItem.HasSubItems, Id = coveoIndexableItem.Id, IsDeletedItem = coveoIndexableItem.IsDeletedItem, ModifiedDate = coveoIndexableItem.ModifiedDate, Parent = coveoIndexableItem.Parent, ParentId = coveoIndexableItem.ParentId, Path = coveoIndexableItem.Path, PrintablePath = coveoIndexableItem.PrintablePath, Title = coveoIndexableItem.Title, }; p_Args.OutputCoveoItems.Add(strippedItem); } ; s_Logger.TraceExiting(); }
private bool IsPreviewRemoverActive(SitecoreIndexableItem sitecoreIndexableItem) { ID activatePreviewRemoverID = new ID(RemovePreviewID); return(sitecoreIndexableItem.GetFieldById(activatePreviewRemoverID).Value.ToString() == CHECKBOX_FIELD_CHECKED_VALUE); }