public void Process(GetDatasourceContentArgs args)
        {
            args.DatasourceItem.Fields.ReadAll();

            foreach (var field in args.DatasourceItem.Fields.Where(field => !field.Name.StartsWith("__")))
            {
                if (!IndexOperationsHelper.IsTextField(new SitecoreItemDataField(field)))
                {
                    continue;
                }

                var fieldValue = StripHtmlTags(field.Value ?? string.Empty);

                if (!string.IsNullOrWhiteSpace(fieldValue))
                {
                    args.Content.Add(fieldValue);
                }
            }

            foreach (Item child in args.DatasourceItem.Children)
            {
                var getDatasourceContentArgs = new GetDatasourceContentArgs(child, args.Content, args.IndexedItem);

                CorePipeline.Run("indexing.getDatasourceContent", getDatasourceContentArgs);
            }
        }
        public object ComputeFieldValue(IIndexable indexable)
        {
            var item = (Item)(indexable as SitecoreIndexableItem);

            Assert.ArgumentNotNull(item, "item");

            if (!ShouldIndexItem(item))
            {
                return(null);
            }
            List <Item> dataSources = Globals.LinkDatabase.GetReferences(item)
                                      .Where(link => ShouldProcessLink(link, item))
                                      .Select(link => link.GetTargetItem())
                                      .Where(targetItem => targetItem != null)
                                      .Distinct().ToList();

            dataSources.Add(item);

            var result = new StringBuilder();

            foreach (var dataSource in dataSources.Where(ShouldIndexDataSource))
            {
                dataSource.Fields.ReadAll();
                foreach (var field in dataSource.Fields.Where(ShouldIndexField))
                {
                    result.AppendLine(IndexOperationsHelper.StripHtml(field.Value));;
                }
            }
            return(result.ToString());
        }
 /// <summary>
 /// Extracts textual content from an item's fields
 /// </summary>
 protected virtual IEnumerable <string> GetItemContent(Item dataSource)
 {
     foreach (Field field in dataSource.Fields)
     {
         if (!IndexOperationsHelper.IsTextField(new SitecoreItemDataField(field)))
         {
             // Use this to handle Rich Text fields
             string fieldValue = StripHtml(field.Value ?? string.Empty);
             if (!string.IsNullOrWhiteSpace(fieldValue))
             {
                 yield return(fieldValue);
             }
         }
     }
 }
Beispiel #4
0
        protected virtual IEnumerable <string> GetItemContent(Item dataSource)
        {
            foreach (Field field in dataSource.Fields)
            {
                // this check is what Sitecore uses to determine if a field belongs in _content (see LuceneDocumentBuilder.AddField())
                if (!IndexOperationsHelper.IsTextField(new SitecoreItemDataField(field)))
                {
                    continue;
                }

                var fieldValue = StringUtil.RemoveTags(field.Value ?? string.Empty);

                if (!string.IsNullOrWhiteSpace(fieldValue))
                {
                    yield return(fieldValue);
                }
            }
        }
        public override void AddField(IIndexableDataField field)
        {
            var fieldName  = field.Name;
            var fieldValue = Index.Configuration.FieldReaders.GetFieldValue(field);

            if (fieldValue == null || (fieldValue is string && string.IsNullOrEmpty(fieldValue.ToString())))
            {
                return;
            }

            var num = BoostingManager.ResolveFieldBoosting(field);

            //name = this.fieldNameTranslator.GetIndexFieldName(name, fieldValue.GetType(), this._culture);
            if (!IsMedia && IndexOperationsHelper.IsTextField(field))
            {
                StoreField(BuiltinFields.Content, fieldValue, true, null);
            }
            StoreField(fieldName, fieldValue, false, num);
        }
        private void CheckAndAddField(IIndexableDataField field)
        {
            string name = field.Name;

            if ((((!this.IsTemplate || !this.Options.HasExcludedTemplateFields) || !this.Options.ExcludedTemplateFields.Contains(field.Name)) && ((!this.IsMedia || !this.Options.HasExcludedMediaFields) || !this.Options.ExcludedMediaFields.Contains(field.Name))) && (!this.Options.ExcludedFields.Contains(field.Id.ToString()) && !this.Options.ExcludedFields.Contains(name)))
            {
                if (this.Options.IndexAllFields)
                {
                    this.AddField(field);
                }
                else if (IndexOperationsHelper.IsTextField(field))
                {
                    this.AddField(field);
                }
                else if (this.Options.IncludedFields.Contains(field.Id.ToString()))
                {
                    this.AddField(field);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Extracts textual content from an item's fields
        /// </summary>
        protected virtual IEnumerable <string> GetItemContent(Item dataSource)
        {
            foreach (Field field in dataSource.Fields)
            {
                // this check is what Sitecore uses to determine if a field belongs in _content (see LuceneDocumentBuilder.AddField())
                if (IndexOperationsHelper.IsTextField(new SitecoreItemDataField(field)))
                {
                    string fieldValue = StripHtml(field.Value ?? string.Empty);

                    if (!string.IsNullOrWhiteSpace(fieldValue))
                    {
                        yield return(fieldValue);
                    }
                }
                else if ((field.Type == "Multilist" || field.Type == "Treelist") && !string.IsNullOrWhiteSpace(field.Value))
                {
                    string[] itemGuids = field.Value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (itemGuids.Any())
                    {
                        foreach (var itemGuid in itemGuids)
                        {
                            var innerItem = dataSource.Database.GetItem(itemGuid, dataSource.Language);
                            foreach (Field innerItemfeild in innerItem.Fields)
                            {
                                if (IndexOperationsHelper.IsTextField(new SitecoreItemDataField(innerItemfeild)))
                                {
                                    string fieldValue = StripHtml(innerItemfeild.Value ?? string.Empty);

                                    if (!string.IsNullOrWhiteSpace(fieldValue))
                                    {
                                        yield return(fieldValue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public override void AddField(IIndexableDataField field)
        {
            AbstractSearchFieldConfiguration fieldConfiguration1 = this.Context.Index.Configuration.FieldMap.GetFieldConfiguration(field);
            object fieldValue = this.Index.Configuration.FieldReaders.GetFieldValue(field);
            string name       = field.Name;
            AzureSearchFieldConfiguration fieldSettings = this.Index.Configuration.FieldMap.GetFieldConfiguration(field) as AzureSearchFieldConfiguration;

            if (fieldSettings == null)
            {
                VerboseLogging.CrawlingLogDebug((Func <string>)(() => string.Format("Cannot resolve field settings for field id:{0}, name:{1}, typeKey:{2} - The field will not be added to the index.", field.Id, (object)field.Name, (object)field.TypeKey)));
            }
            else
            {
                object obj   = fieldConfiguration1.FormatForWriting(fieldValue);
                float  boost = BoostingManager.ResolveFieldBoosting(field);
                if (IndexOperationsHelper.IsTextField(field))
                {
                    AzureSearchFieldConfiguration fieldConfiguration2 = this.Index.Configuration.FieldMap.GetFieldConfiguration("_content") as AzureSearchFieldConfiguration;
                    this.AddField("_content", obj, fieldConfiguration2 ?? this.defaultTextField, 0.0f);
                }
                this.AddField(name, obj, fieldSettings, boost);
            }
        }
 private bool IsTextField(Field field)
 {
     return(IndexOperationsHelper.IsTextField((SitecoreItemDataField)field));
 }