예제 #1
0
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = indexableField as SitecoreItemDataField;

            var list = new List <string>();

            var multiField = FieldTypeManager.GetField(field) as MultilistField;

            if (multiField != null)
            {
                foreach (string key in multiField.List)
                {
                    string itm = key;

                    if (ID.IsID(itm))
                    {
                        itm = ShortID.Encode(itm).ToLowerInvariant();
                        list.Add(itm);
                    }
                }

                return(list);
            }

            return(list);
        }
예제 #2
0
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            if (!(indexableField is SitecoreItemDataField))
            {
                return(indexableField.Value);
            }
            Field field = indexableField as SitecoreItemDataField;

            if (!string.IsNullOrEmpty(field.Value))
            {
                string text = field.Value;

                int intResult;

                if (int.TryParse(text, out intResult))
                {
                    return(intResult);
                }

                if (text.Count((char x) => x == ',') == 1)
                {
                    text = text.Replace(',', '.');
                }
                double num;
                if (double.TryParse(text, System.Globalization.NumberStyles.Float,
                                    System.Globalization.CultureInfo.InvariantCulture, out num))
                {
                    return(num);
                }
            }
            return(0);
        }
예제 #3
0
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = indexableField as SitecoreItemDataField;

            var list = new List<string>();

            var multiField = FieldTypeManager.GetField(field) as MultilistField;

            if (multiField != null)
            {
                foreach (string key in multiField.List)
                {
                    string itm = key;

                    if (ID.IsID(itm))
                    {
                        itm = ShortID.Encode(itm).ToLowerInvariant();
                        list.Add(itm);
                    }
                }

                return list;
            }

            return list;
        }
        public override object GetFieldValue(IIndexableDataField field)
        {
            Field field1 = (Field)(field as SitecoreItemDataField);

            if (field1 != null)
            {
                if (string.IsNullOrEmpty(field1.Value))
                {
                    return((object)null);
                }
                if (FieldTypeManager.GetField(field1) is DateField)
                {
                    DateField dateField = new DateField(field1);
                    if (dateField.DateTime > DateTime.MinValue)
                    {
                        return((object)dateField.DateTime);
                    }
                }
            }
            else if (field.Value is DateTime)
            {
                return((object)(DateTime)field.Value);
            }
            return((object)null);
        }
예제 #5
0
        private void CheckAndAddField(IIndexable indexable, IIndexableDataField field)
        {
            var name = field.Name;

            if (IsTemplate && Options.HasExcludedTemplateFields && (Options.ExcludedTemplateFields.Contains(name) || Options.ExcludedTemplateFields.Contains(field.Id.ToString())))
            {
                VerboseLogging.CrawlingLogDebug(() => string.Format("Skipping field id:{0}, name:{1}, typeKey:{2} - Field was excluded.", field.Id, field.Name, field.TypeKey));
            }
            else if (IsMedia && Options.HasExcludedMediaFields && Options.ExcludedMediaFields.Contains(field.Name))
            {
                VerboseLogging.CrawlingLogDebug(() => string.Format("Skipping field id:{0}, name:{1}, typeKey:{2} - Media field was excluded.", field.Id, field.Name, field.TypeKey));
            }
            else
            {
                if (!Options.ExcludedFields.Contains(field.Id.ToString()))
                {
                    if (!Options.ExcludedFields.Contains(name))
                    {
                        try
                        {
                            if (Options.IndexAllFields)
                            {
                                using (new LanguageFallbackFieldSwitcher(new bool?(Index.EnableFieldLanguageFallback)))
                                {
                                    AddField(field);
                                    return;
                                }
                            }
                            else if (Options.IncludedFields.Contains(name) || Options.IncludedFields.Contains(field.Id.ToString()))
                            {
                                using (new LanguageFallbackFieldSwitcher(new bool?(Index.EnableFieldLanguageFallback)))
                                {
                                    AddField(field);
                                    return;
                                }
                            }
                            else
                            {
                                VerboseLogging.CrawlingLogDebug(() => string.Format("Skipping field id:{0}, name:{1}, typeKey:{2} - Field was not included.", field.Id, field.Name, field.TypeKey));
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            if (!Settings.StopOnCrawlFieldError())
                            {
                                CrawlingLog.Log.Fatal(string.Format("Could not add field {1} : {2} for indexable {0}", indexable.UniqueId, field.Id, field.Name), ex);
                                return;
                            }
                            throw;
                        }
                    }
                }
                VerboseLogging.CrawlingLogDebug(() => string.Format("Skipping field id:{0}, name:{1}, typeKey:{2} - Field was excluded.", field.Id, field.Name, field.TypeKey));
            }
        }
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            if (!(indexableField is SitecoreItemDataField))
                return indexableField.Value;
            var field = (Field)(indexableField as SitecoreItemDataField);
            if (!string.IsNullOrEmpty(field.Value))
                return new SpatialPoint(field.Value);

            return null;
        }
 private bool ShouldAddField(IIndexableDataField field)
 {
     if (!base.Index.Configuration.IndexAllFields)
     {
         if (field.Value == null)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #8
0
        public override object GetFieldValue(IIndexableDataField field)
        {
            var tags = field.Value.ToString().Split(',');

            for (var i = 0; i < tags.Length; i++)
            {
                tags[i] = tags[i].Trim();
            }

            return(tags.ToList());
        }
 public override object GetFieldValue(IIndexableDataField field)
 {
     Field field1 = (Field)(field as SitecoreItemDataField);
     if (field1 != null)
     {
         CheckboxField checkboxField = FieldTypeManager.GetField(field1) as CheckboxField;
         return (checkboxField == null ? 0 : (checkboxField.Checked ? 1 : 0));
     }
     if (field.Value is bool)
         return field.Value;
     return field.Value;
 }
 public override object GetFieldValue(IIndexableDataField field)
 {
     Assert.ArgumentNotNull((object)field, "field");
     if (field.Value is string)
     {
         string s = (string)field.Value;
         long result;
         if (!string.IsNullOrEmpty(s) && long.TryParse(s, out result))
             return (object)result;
     }
     else if (field.Value is long || field.Value is ulong || (field.Value is short || field.Value is ushort) || (field.Value is int || field.Value is uint || field.Value is byte))
         return field.Value;
     return (object)null;
 }
 private bool ShouldAddField(IIndexableDataField field, XmlFieldConfiguration config)
 {
     if (!base.Index.Configuration.IndexAllFields)
     {
         if (config == null || (config.FieldName == null && config.FieldTypeName == null))
         {
             return(false);
         }
         if (field.Value == null)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #12
0
        public override object GetFieldValue(IIndexableDataField field)
        {
            Field field1 = (Field)(field as SitecoreItemDataField);

            if (field1 != null)
            {
                CheckboxField checkboxField = FieldTypeManager.GetField(field1) as CheckboxField;
                return(checkboxField == null ? 0 : (checkboxField.Checked ? 1 : 0));
            }
            if (field.Value is bool)
            {
                return(field.Value);
            }
            return(field.Value);
        }
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            if (!(indexableField is SitecoreItemDataField))
            {
                return(indexableField.Value);
            }
            var field = (Field)(indexableField as SitecoreItemDataField);

            if (!string.IsNullOrEmpty(field.Value))
            {
                return(new SpatialPoint(field.Value));
            }

            return(null);
        }
예제 #14
0
        public AbstractSearchFieldConfiguration GetFieldConfiguration(IIndexableDataField field)
        {
            Assert.ArgumentNotNull(field, "field");

            ElasticSearchFieldConfiguration configuration;

            if (_fieldNameMap.TryGetValue(field.Name.ToLowerInvariant(), out configuration))
            {
                return(configuration);
            }
            if (_fieldTypeNameMap.TryGetValue(field.TypeKey.ToLowerInvariant(), out configuration))
            {
                return(configuration);
            }
            return(_elasticSearchFieldDefault);
        }
예제 #15
0
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = (indexableField as SitecoreItemDataField);

            var strongTypeField = FieldTypeManager.GetField(field);

            if (strongTypeField is LookupField)
            {
                return(GetRefernceValue(new LookupField(field).TargetItem));
            }
            if (strongTypeField is ReferenceField)
            {
                return(GetRefernceValue(new ReferenceField(field).TargetItem));
            }

            return(null);
        }
        public override void AddField(IIndexableDataField field)
        {
            if (!ShouldAddField(field))
            {
                return;
            }

            var reader = base.Index.Configuration.FieldReaders.GetFieldReader(field);
            var value  = reader.GetFieldValue(field);

            if (value == null)
            {
                return;
            }

            AddField(field.Name, value);
        }
 public override object GetFieldValue(IIndexableDataField field)
 {
     Assert.ArgumentNotNull((object)field, "field");
     if (field.Value is string)
     {
         string s = (string)field.Value;
         long   result;
         if (!string.IsNullOrEmpty(s) && long.TryParse(s, out result))
         {
             return((object)result);
         }
     }
     else if (field.Value is long || field.Value is ulong || (field.Value is short || field.Value is ushort) || (field.Value is int || field.Value is uint || field.Value is byte))
     {
         return(field.Value);
     }
     return((object)null);
 }
 public override object GetFieldValue(IIndexableDataField field)
 {
     Field field1 = (Field)(field as SitecoreItemDataField);
     if (field1 != null)
     {
         if (string.IsNullOrEmpty(field1.Value))
             return (object)null;
         if (FieldTypeManager.GetField(field1) is DateField)
         {
             DateField dateField = new DateField(field1);
             if (dateField.DateTime > DateTime.MinValue)
                 return (object)dateField.DateTime;
         }
     }
     else if (field.Value is DateTime)
         return (object)(DateTime)field.Value;
     return (object)null;
 }
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field     field     = indexableField as SitecoreItemDataField;
            DateField dateField = FieldTypeManager.GetField(field) as DateField;

            if (dateField != null)
            {
                var date = dateField.DateTime;

                if (date == DateTime.MinValue)
                {
                    return(null);
                }

                return((Int32)(date.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
            }
            return(null);
        }
        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);
                }
            }
        }
예제 #22
0
        /// <summary>
        ///     The get field value.
        /// </summary>
        /// <param name="field">
        ///     The field.
        /// </param>
        /// <returns>
        ///     The <see cref="object" />.
        /// </returns>
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = indexableField as SitecoreItemDataField;

            var list = new List <string>();

            if (field != null)
            {
                foreach (string key in field.Value.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string itm = key;

                    if (ID.IsID(itm))
                    {
                        itm = ShortID.Encode(itm).ToLowerInvariant();
                        list.Add(itm);
                    }
                }
            }

            return(list);
        }
        /// <summary>
        ///     The get field value.
        /// </summary>
        /// <param name="field">
        ///     The field.
        /// </param>
        /// <returns>
        ///     The <see cref="object" />.
        /// </returns>
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = indexableField as SitecoreItemDataField;

            var list = new List<string>();

            if (field != null)
            {
                foreach (string key in field.Value.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries))
                {
                    string itm = key;

                    if (ID.IsID(itm))
                    {
                        itm = ShortID.Encode(itm).ToLowerInvariant();
                        list.Add(itm);
                    }
                }
            }

            return list;
        }
        /// <summary>
        ///     The get field value.
        /// </summary>
        /// <param name="field">
        ///     The field.
        /// </param>
        /// <returns>
        ///     The <see cref="object" />.
        /// </returns>
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = indexableField as SitecoreItemDataField;

            var list = new List<int>();

            if (field != null)
            {
                string[] range = field.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                foreach (string number in range)
                {
                    int currentNumber;
                    if (!string.IsNullOrEmpty(number) && int.TryParse(number, out currentNumber))
                    {
                        list.Add(currentNumber);
                    }
                }
            }

            return list;
        }
예제 #25
0
        /// <summary>
        ///     The get field value.
        /// </summary>
        /// <param name="field">
        ///     The field.
        /// </param>
        /// <returns>
        ///     The <see cref="object" />.
        /// </returns>
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = indexableField as SitecoreItemDataField;

            var list = new List <int>();

            if (field != null)
            {
                string[] range = field.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                foreach (string number in range)
                {
                    int currentNumber;
                    if (!string.IsNullOrEmpty(number) && int.TryParse(number, out currentNumber))
                    {
                        list.Add(currentNumber);
                    }
                }
            }

            return(list);
        }
        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);
            }
        }
        public override object GetFieldValue(IIndexableDataField indexableField)
        {
            Field field = indexableField as SitecoreItemDataField;

            if (string.IsNullOrWhiteSpace(field?.Value))
            {
                return(null);
            }

            var values = field.Value.Split(',');

            if (values.Length < 2)
            {
                return(null);
            }

            double lat, lng;

            if (double.TryParse(values[0], out lat) &&
                double.TryParse(values[1], out lng))
            {
                var location = new JObject
                {
                    ["lat"] = lat,
                    ["lng"] = lng
                };

                var result = new JObject {
                    ["_geoloc"] = location
                };

                return(result);
            }

            return(null);
        }
        public override void AddField(IIndexableDataField field)
        {
            var fieldConfig = base.Index.Configuration.FieldMap.GetFieldConfiguration(field) as XmlFieldConfiguration;

            if (fieldConfig == null || !ShouldAddField(field, fieldConfig))
            {
                return;
            }
            var tag    = new XElement("field");
            var reader = base.Index.Configuration.FieldReaders.GetFieldReader(field);
            var value  = reader.GetFieldValue(field).ToString();

            if (fieldConfig.StoreAsCdata)
            {
                tag.Add(new XCData(value));
            }
            else
            {
                tag.Value = value;
            }
            tag.SetAttributeValue("name", reader.GetIndexFieldName(field));
            tag.SetAttributeValue("id", field.Id.ToString());
            this.Document.Root.Add(tag);
        }
예제 #29
0
 public AbstractSearchFieldConfiguration GetFieldConfiguration(IIndexableDataField field, Func <AbstractSearchFieldConfiguration, bool> fieldVisitorFunc)
 {
     throw new NotImplementedException();
 }
        /// <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();
        }
예제 #31
0
 public AbstractSearchFieldConfiguration GetFieldConfiguration(IIndexableDataField field)
 {
     throw new NotImplementedException();
 }
 public override void AddField(IIndexableDataField field)
 {
     throw new NotImplementedException();
 }
예제 #33
0
 public abstract void AddField(IIndexableDataField field);