/// <summary> /// Gets whether the item to index has a layout. /// </summary> /// <param name="p_Item">The item to index.</param> /// <returns><c>true</c> if the item has a layout, <c>false</c> otherwise.</returns> private bool ItemHasLayout(CoveoIndexableItem p_Item) { bool itemHasLayout = false; object hasLayoutMetadata; if (p_Item.Metadata.TryGetValue(MetadataNames.s_HasLayout, out hasLayoutMetadata)) { itemHasLayout = hasLayoutMetadata.Equals("1"); } return(itemHasLayout); }
/// <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(); }
/// <inheritDoc /> public void Process(CoveoPostItemProcessingPipelineArgs p_Args) { s_Logger.TraceEntering(); Precondition.NotNull(p_Args, () => () => p_Args); ID limitedAccessFieldId = new ID(LimitedAccessFieldId); ID fieldToHideId = new ID(FieldToHideId); ID previewFieldId = new ID(PreviewFieldId); CoveoIndexableItem coveoIndexableItem = p_Args.CoveoItem; SitecoreIndexableItem sitecoreIndexableItem = p_Args.Item as SitecoreIndexableItem; if (coveoIndexableItem != null && sitecoreIndexableItem != null && !sitecoreIndexableItem.Item.Paths.IsMediaItem && sitecoreIndexableItem.Item[limitedAccessFieldId] == LIMITED_ACCESS_VALUE) { // Check if a preview text has been specified. IIndexableDataField previewField = sitecoreIndexableItem.Fields.FirstOrDefault(arg => (ID)arg.Id == previewFieldId); byte[] encodedPreview = null; if (previewField != null) { string previewText = previewField.Value.ToString(); if (!String.IsNullOrEmpty(previewText)) { encodedPreview = Encoding.UTF8.GetBytes(previewText); } } // Duplicates metadata. Dictionary <string, object> newMetadata = new Dictionary <string, object>(coveoIndexableItem.Metadata) { { LIMITED_ACCESS_METADATA_FIELDNAME, true } }; // Add a hidden field containing the original binary data for relevance if (coveoIndexableItem.BinaryData != null) { newMetadata.Add(HIDDEN_CONTENT_METADATA_FIELDNAME, Encoding.UTF8.GetString(coveoIndexableItem.BinaryData)); } if (!String.IsNullOrEmpty(FieldToHideId)) { IIndexableDataField fieldToHide = sitecoreIndexableItem.Fields.FirstOrDefault(arg => (ID)arg.Id == fieldToHideId); if (fieldToHide != null) { newMetadata.Remove(fieldToHide.Name); } } string newUniqueId = coveoIndexableItem.UniqueId + LIMITED_ACCESS_ITEM_SUFFIX; CoveoIndexableItem strippedItem = new CoveoIndexableItem { // Custom fields. // Replace the data with the preview text. This way, the preview will be used for the new item's quickview. BinaryData = encodedPreview, UniqueId = newUniqueId, Metadata = newMetadata, // Fields that are inherited from the parent item. 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, Permissions = CreateAnonymousAccessRule(), PrintablePath = coveoIndexableItem.PrintablePath, Title = coveoIndexableItem.Title }; p_Args.OutputCoveoItems.Add(strippedItem); } s_Logger.TraceExiting(); }