Example #1
0
 /// <summary>
 /// Process field data building up index data in XML format
 /// </summary>
 /// <param name="fields">Fields to process</param>
 /// <param name="settings">Custom settings for this set of fields (if not null overrides default settings)</param>
 public virtual void ProcessData(ItemFields fields, FieldProcessorSettings settings = null)
 {
     if (settings == null)
     {
         settings = DefaultSettings;
     }
     //use defaults if fields are not explicitly included/excluded
     if (settings.ExcludeByDefault == null)
     {
         settings.ExcludeByDefault = DefaultSettings.ExcludeByDefault;
         if (settings.ManagedFields == null)
         {
             settings.ManagedFields = DefaultSettings.ManagedFields;
         }
     }
     if (settings.ManagedFields == null)
     {
         settings.ManagedFields = new List<string>();
     }
     if (settings.FieldMap == null)
     {
         settings.FieldMap = DefaultSettings.FieldMap;
     }
     if (settings.LinkFieldsToEmbed == null)
     {
         settings.LinkFieldsToEmbed = DefaultSettings.LinkFieldsToEmbed;
     }
     ProcessFields(fields, settings);
 }
Example #2
0
        /// <summary>
        /// Process a field into a custom index data element
        /// </summary>
        /// <param name="field">The field to process</param>
        /// <param name="settings">field processor settings</param>
        public virtual void ProcessCustomField(ItemField field, FieldProcessorSettings settings = null)
        {
            IndexField targetField = settings.CustomFieldTarget(field.Name);
            //indexing behaviour is more specific for custom fields:
            //1. For keyword or component link fields, the kw or linked component item id is indexed
            //2. For date fields, the date (in standard format) is indexed
            //3. For number fields the number is indexed
            //4. For text fields, the text content (no markup) is indexed
            IList <string> values = new List <string>();

            if (field is KeywordField)
            {
                values = ((KeywordField)field).Values.Select(k => k.Id.ItemId.ToString()).ToList();
            }
            else if (field is ComponentLinkField)
            {
                values = ((ComponentLinkField)field).Values.Select(c => c.Id.ItemId.ToString()).ToList();
            }
            else if (field is DateField)
            {
                values = ((DateField)field).Values.Select(d => d.ToString("o") + "Z").ToList();
            }
            else if (field is NumberField)
            {
                values = ((NumberField)field).Values.Select(n => n.ToString()).ToList();
            }
            else if (field is TextField)
            {
                values = ((TextField)field).Values;
            }
            AddToData(values, (field is XhtmlField), targetField);
        }
Example #3
0
 /// <summary>
 /// Process field data building up index data in XML format
 /// </summary>
 /// <param name="fields">Fields to process</param>
 /// <param name="settings">Custom settings for this set of fields (if not null overrides default settings)</param>
 public virtual void ProcessData(ItemFields fields, FieldProcessorSettings settings = null)
 {
     if (settings == null)
     {
         settings = DefaultSettings;
     }
     //use defaults if fields are not explicitly included/excluded
     if (settings.ExcludeByDefault == null)
     {
         settings.ExcludeByDefault = DefaultSettings.ExcludeByDefault;
         if (settings.ManagedFields == null)
         {
             settings.ManagedFields = DefaultSettings.ManagedFields;
         }
     }
     if (settings.ManagedFields == null)
     {
         settings.ManagedFields = new List <string>();
     }
     if (settings.FieldMap == null)
     {
         settings.FieldMap = DefaultSettings.FieldMap;
     }
     if (settings.LinkFieldsToEmbed == null)
     {
         settings.LinkFieldsToEmbed = DefaultSettings.LinkFieldsToEmbed;
     }
     ProcessFields(fields, settings);
 }
Example #4
0
 /// <summary>
 /// Prepare index data for any item metadata
 /// </summary>
 /// <param name="item">The item to process</param>
 /// <param name="settings">Field processor settings</param>
 public virtual void ProcessMetadata(RepositoryLocalObject item, FieldProcessorSettings settings)
 {
     if (item.Metadata != null)
     {
         ItemFields fields = new ItemFields(item.Metadata, item.MetadataSchema);
         _processor.ProcessData(fields, settings);
     }
 }
Example #5
0
 public FieldProcessor()
 {
     IndexData = new XmlDocument();
     IndexData.LoadXml("<data><body></body><custom></custom></data>");
     DefaultSettings = new FieldProcessorSettings {
         ExcludeByDefault = false, ManagedFields = new List <string>(), FieldMap = new Dictionary <string, IndexField>()
     };
 }
Example #6
0
        /// <summary>
        /// Prepare index data for a component presentation
        /// </summary>
        /// <param name="cp">Component Presentation to process</param>
        /// <param name="flaggedDcps">List of already processed CPs, to avoid processing the same DCP more than once</param>
        public virtual void ProcessComponentPresentation(ComponentPresentation cp, List <string> flaggedDcps)
        {
            string id = GetDcpIdentifier(cp);

            if (cp.ComponentTemplate.IsIndexed(_processor.MinimumComponentTemplatePrio) && (flaggedDcps == null || !flaggedDcps.Contains(id)))
            {
                this.Url = GetUrlForDcp(cp);
                FieldProcessorSettings settings = cp.ComponentTemplate.GetFieldProcessorSettings();
                ProcessComponent(cp.Component, settings);
            }
        }
Example #7
0
 /// <summary>
 /// Process an individual field
 /// </summary>
 /// <param name="field">The field to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessField(ItemField field, FieldProcessorSettings settings)
 {
     if (settings.HasCustomMapping(field.Name))
     {
         ProcessCustomField(field, settings);
     }
     else
     {
         ProcessCatchAllField(field, settings);
     }
 }
Example #8
0
 /// <summary>
 /// Prepare index data for a component
 /// </summary>
 /// <param name="comp">The component to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessComponentData(Component component, FieldProcessorSettings settings)
 {
     _processor.SetComponentAsProcessed(component.Id);
     if (component.IsIndexed())
     {
         if (component.Content != null)
         {
             ItemFields fields = new ItemFields(component.Content, component.Schema);
             _processor.ProcessData(fields, settings);
         }
         ProcessMetadata(component, settings);
     }
 }
Example #9
0
        /// <summary>
        /// Prepare index data for a Page
        /// </summary>
        /// <param name="page">The page to process</param>
        /// <returns>List of processed DCPs - can be used to prevent DCPs being indexed multiple times (both in page and CP rendering)</returns>
        public virtual List <string> ProcessPage(Page page)
        {
            List <string> processedDcps = new List <string>();

            if (page.IsIndexed() && page.PageTemplate.IsIndexed() && page.OrganizationalItem.IsIndexed())
            {
                this.Url           = page.PublishLocationUrl;
                this.SchemaId      = FetchSchemaId(page);
                this.PublicationId = page.ContextRepository.Id.ItemId;
                this.ItemType      = 64;
                this.ParentSGId    = page.OrganizationalItem.Id.ItemId;
                StructureGroups    = new List <int>();
                var sg = page.OrganizationalItem;
                while (sg != null && sg is StructureGroup)
                {
                    StructureGroups.Add(sg.Id.ItemId);
                    sg = sg.OrganizationalItem;
                }
                ProcessPageMetadata(page);
                List <ComponentPresentation> cps = GatherAllCpsFromPage(page);
                foreach (var cp in cps)
                {
                    if (cp.ComponentTemplate.IsIndexed(_processor.MinimumComponentTemplatePrio))
                    {
                        FieldProcessorSettings settings = cp.ComponentTemplate.GetFieldProcessorSettings();
                        ProcessComponentData(cp.Component, settings);
                        _hasIndexData = true;
                        //To avoid DCPs embedded on pages being indexed twice in the same publish transaction
                        //(once in the page index data and again in their own index data)
                        //we return identifiers to the template, to add to context variables
                        if (cp.ComponentTemplate.IsRepositoryPublishable)
                        {
                            processedDcps.Add(GetDcpIdentifier(cp));
                        }
                    }
                }

                if (String.IsNullOrEmpty(_processor.Title))
                {
                    this.Title = page.Title;
                }
                else
                {
                    this.Title = _processor.Title;
                }
            }

            return(processedDcps);
        }
Example #10
0
 /// <summary>
 /// Prepare index data for a component, as part of a dynamic component presentation
 /// </summary>
 /// <param name="comp">The component to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessComponent(Component comp, FieldProcessorSettings settings)
 {
     if (comp.IsIndexed())
     {
         this.PublicationId = comp.ContextRepository.Id.ItemId;
         this.ItemType      = 16;
         this.SchemaId      = comp.Schema.Id.ItemId;
         ProcessComponentData(comp, settings);
         _hasIndexData = true;
         if (String.IsNullOrEmpty(_processor.Title))
         {
             this.Title = comp.Title;
         }
         else
         {
             this.Title = _processor.Title;
         }
     }
 }
Example #11
0
 /// <summary>
 /// Process a field into the catchall index data
 /// </summary>
 /// <param name="field">The field to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessCatchAllField(ItemField field, FieldProcessorSettings settings = null)
 {
     //only process text fields
     if (field is TextField)
     {
         AddToData(((TextField)field).Values, (field is XhtmlField));
     }
     if (field is ComponentLinkField && settings.IsLinkToBeFollowed(field.Name))
     {
         foreach (var comp in ((ComponentLinkField)field).Values)
         {
             //avoid circular links, and indexing the items that are linked more than once
             if (!IsComponentAlreadyProcessed(comp.Id))
             {
                 SetComponentAsProcessed(comp.Id);
                 ProcessData(new ItemFields(comp.Content, comp.Schema), settings);
             }
         }
     }
 }
Example #12
0
 /// <summary>
 /// Process item fields
 /// </summary>
 /// <param name="fields">Fields to process</param>
 /// <param name="settings">Field processor settings</param>
 public virtual void ProcessFields(ItemFields fields, FieldProcessorSettings settings)
 {
     foreach (var field in fields)
     {
         if (field is EmbeddedSchemaField)
         {
             foreach (var subfields in (field as EmbeddedSchemaField).Values)
             {
                 ProcessFields(subfields, settings);
             }
         }
         else
         {
             //A field is indexed if we are excluding by default and the field is in the set of managed fields,
             //OR we are including by default and the field is NOT in the set of managed fields
             //OR there is a mapping for it in the custom field map
             if ((settings.ExcludeByDefault == settings.ManagedFields.Contains(field.Name)) || settings.FieldMap.ContainsKey(field.Name))
             {
                 ProcessField(field, settings);
             }
         }
     }
 }
Example #13
0
 /// <summary>
 /// Load field processor settings from template metadata
 /// </summary>
 /// <param name="template">The template to process</param>
 /// <returns>field processor setting specific to this template</returns>
 public static FieldProcessorSettings GetFieldProcessorSettings(this Template template)
 {
     FieldProcessorSettings settings = new FieldProcessorSettings();
     if (template.Metadata != null)
     {
         settings.SetFieldMap(GetFieldValue(template.Metadata,Constants.FIELD_CUSTOMFIELDMAP));
         settings.SetManagedFields(GetFieldValue(template.Metadata, Constants.FIELD_MANAGEDFIELDS));
         settings.SetLinkFieldsToEmbedFields(GetFieldValue(template.Metadata, Constants.FIELD_LINKFIELDSTOEMBED));
         string includeExclude = GetFieldValue(template.Metadata, Constants.FIELD_INCLUDEEXCLUDE);
         if (includeExclude!=null)
         {
             if (includeExclude.ToLower().Contains(Constants.FIELDVALUE_INCLUDE))
             {
                 settings.ExcludeByDefault = false;
             }
             else if (includeExclude.ToLower().Contains(Constants.FIELDVALUE_EXCLUDE))
             {
                 settings.ExcludeByDefault = true;
             }
         }
     }
     return settings;
 }
Example #14
0
        /// <summary>
        /// Load field processor settings from template metadata
        /// </summary>
        /// <param name="template">The template to process</param>
        /// <returns>field processor setting specific to this template</returns>
        public static FieldProcessorSettings GetFieldProcessorSettings(this Template template)
        {
            FieldProcessorSettings settings = new FieldProcessorSettings();

            if (template.Metadata != null)
            {
                settings.SetFieldMap(GetFieldValue(template.Metadata, Constants.FIELD_CUSTOMFIELDMAP));
                settings.SetManagedFields(GetFieldValue(template.Metadata, Constants.FIELD_MANAGEDFIELDS));
                settings.SetLinkFieldsToEmbedFields(GetFieldValue(template.Metadata, Constants.FIELD_LINKFIELDSTOEMBED));
                string includeExclude = GetFieldValue(template.Metadata, Constants.FIELD_INCLUDEEXCLUDE);
                if (includeExclude != null)
                {
                    if (includeExclude.ToLower().Contains(Constants.FIELDVALUE_INCLUDE))
                    {
                        settings.ExcludeByDefault = false;
                    }
                    else if (includeExclude.ToLower().Contains(Constants.FIELDVALUE_EXCLUDE))
                    {
                        settings.ExcludeByDefault = true;
                    }
                }
            }
            return(settings);
        }
Example #15
0
 /// <summary>
 /// Process item fields
 /// </summary>
 /// <param name="fields">Fields to process</param>
 /// <param name="settings">Field processor settings</param>
 public virtual void ProcessFields(ItemFields fields, FieldProcessorSettings settings)
 {
     foreach (var field in fields)
     {
         if (field is EmbeddedSchemaField)
         {
             foreach (var subfields in (field as EmbeddedSchemaField).Values)
             {
                 ProcessFields(subfields, settings);
             }
         }
         else
         {
             //A field is indexed if we are excluding by default and the field is in the set of managed fields,
             //OR we are including by default and the field is NOT in the set of managed fields
             //OR there is a mapping for it in the custom field map
             if ((settings.ExcludeByDefault == settings.ManagedFields.Contains(field.Name)) || settings.FieldMap.ContainsKey(field.Name))
             {
                 ProcessField(field, settings);
             }
         }
     }
 }
Example #16
0
 /// <summary>
 /// Prepare index data for a component
 /// </summary>
 /// <param name="comp">The component to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessComponentData(Component component, FieldProcessorSettings settings)
 {
     _processor.SetComponentAsProcessed(component.Id);
     if (component.IsIndexed())
     {
         if (component.Content != null)
         {
             ItemFields fields = new ItemFields(component.Content, component.Schema);
             _processor.ProcessData(fields, settings);
         }
         ProcessMetadata(component, settings);
     }
 }
Example #17
0
 /// <summary>
 /// Prepare index data for any item metadata
 /// </summary>
 /// <param name="item">The item to process</param>
 /// <param name="settings">Field processor settings</param>
 public virtual void ProcessMetadata(RepositoryLocalObject item, FieldProcessorSettings settings)
 {
     if (item.Metadata != null)
     {
         ItemFields fields = new ItemFields(item.Metadata, item.MetadataSchema);
         _processor.ProcessData(fields, settings);
     }
 }
Example #18
0
 /// <summary>
 /// Prepare index data for a component, as part of a dynamic component presentation
 /// </summary>
 /// <param name="comp">The component to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessComponent(Component comp, FieldProcessorSettings settings)
 {
     if (comp.IsIndexed())
     {
         this.PublicationId = comp.ContextRepository.Id.ItemId;
         this.ItemType = 16;
         this.SchemaId = comp.Schema.Id.ItemId;
         ProcessComponentData(comp, settings);
         _hasIndexData = true;
         if (String.IsNullOrEmpty(_processor.Title))
         {
             this.Title = comp.Title;
         }
         else
         {
             this.Title = _processor.Title;
         }
     }
 }
Example #19
0
 /// <summary>
 /// Process a field into the catchall index data
 /// </summary>
 /// <param name="field">The field to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessCatchAllField(ItemField field, FieldProcessorSettings settings = null)
 {
     //only process text fields
     if (field is TextField)
     {
         AddToData(((TextField)field).Values, (field is XhtmlField));
     }
     if (field is ComponentLinkField && settings.IsLinkToBeFollowed(field.Name))
     {
         foreach (var comp in ((ComponentLinkField)field).Values)
         {
             //avoid circular links, and indexing the items that are linked more than once
             if (!IsComponentAlreadyProcessed(comp.Id))
             {
                 SetComponentAsProcessed(comp.Id);
                 ProcessData(new ItemFields(comp.Content, comp.Schema), settings);
             }
         }
     }
 }
Example #20
0
 /// <summary>
 /// Process a field into a custom index data element
 /// </summary>
 /// <param name="field">The field to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessCustomField(ItemField field, FieldProcessorSettings settings = null)
 {
     IndexField targetField = settings.CustomFieldTarget(field.Name);
     //indexing behaviour is more specific for custom fields:
     //1. For keyword or component link fields, the kw or linked component item id is indexed
     //2. For date fields, the date (in standard format) is indexed
     //3. For number fields the number is indexed
     //4. For text fields, the text content (no markup) is indexed
     IList<string> values = new List<string>();
     if (field is KeywordField)
     {
         values = ((KeywordField)field).Values.Select(k => k.Id.ItemId.ToString()).ToList();
     }
     else if (field is ComponentLinkField)
     {
         values = ((ComponentLinkField)field).Values.Select(c => c.Id.ItemId.ToString()).ToList();
     }
     else if (field is DateField)
     {
         values = ((DateField)field).Values.Select(d => d.ToString("o") + "Z").ToList();
     }
     else if (field is NumberField)
     {
         values = ((NumberField)field).Values.Select(n => n.ToString()).ToList();
     }
     else if (field is TextField)
     {
         values = ((TextField)field).Values;
     }
     AddToData(values, (field is XhtmlField), targetField);
 }
Example #21
0
        /// <summary>
        /// Prepare index data for page metadata
        /// </summary>
        /// <param name="page">The page to process</param>
        public virtual void ProcessPageMetadata(Page page)
        {
            FieldProcessorSettings settings = page.PageTemplate.GetFieldProcessorSettings();

            ProcessMetadata(page, settings);
        }
Example #22
0
 public FieldProcessor()
 {
     IndexData = new XmlDocument();
     IndexData.LoadXml("<data><body></body><custom></custom></data>");
     DefaultSettings = new FieldProcessorSettings { ExcludeByDefault = false, ManagedFields = new List<string>(), FieldMap = new Dictionary<string, IndexField>() };
 }
Example #23
0
 /// <summary>
 /// Process an individual field
 /// </summary>
 /// <param name="field">The field to process</param>
 /// <param name="settings">field processor settings</param>
 public virtual void ProcessField(ItemField field, FieldProcessorSettings settings)
 {
     if (settings.HasCustomMapping(field.Name))
     {
         ProcessCustomField(field, settings);
     }
     else
     {
         ProcessCatchAllField(field, settings);
     }
 }