public IndexMetadata(string name, string target, IndexKind kind, IDictionary<string, string> options)
 {
     Name = name;
     Target = target;
     Kind = kind;
     Options = options;
 }
 public IndexMetadata(string name, string target, IndexKind kind, IDictionary <string, string> options)
 {
     Name    = name;
     Target  = target;
     Kind    = kind;
     Options = options;
 }
Beispiel #3
0
        private static void Add(Document document, string fieldName, string value, IndexKind indexKind)
        {
            if (value == null)
            {
                return;
            }

            bool fullText = indexKind.HasFlag(IndexKind.FullText);
            bool store    = fullText || indexKind.HasFlag(IndexKind.Store);
            bool index    = fullText || indexKind.HasFlag(IndexKind.Index);
            var  field    = new Field(
                name: fieldName,
                value: value,
                store: store ? Field.Store.YES : Field.Store.NO,
                index: index ? Field.Index.ANALYZED : Field.Index.NO,
                termVector: fullText ? Field.TermVector.WITH_POSITIONS_OFFSETS : Field.TermVector.NO);

            document.Add(field);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Index"/> class for the Azure Cosmos DB service.
 /// </summary>
 protected Index(IndexKind kind)
 {
     this.Kind = kind;
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (objectType != typeof(Index))
            {
                return(null);
            }

            JToken indexToken = JToken.Load(reader);

            if (indexToken.Type == JTokenType.Null)
            {
                return(null);
            }

            if (indexToken.Type != JTokenType.Object)
            {
                throw new JsonSerializationException(
                          string.Format(CultureInfo.CurrentCulture, Documents.RMResources.InvalidIndexSpecFormat));
            }

            JToken indexKindToken = indexToken[Documents.Constants.Properties.IndexKind];

            if (indexKindToken == null || indexKindToken.Type != JTokenType.String)
            {
                throw new JsonSerializationException(
                          string.Format(CultureInfo.CurrentCulture, Documents.RMResources.InvalidIndexSpecFormat));
            }

            IndexKind indexKind = IndexKind.Hash;

            if (Enum.TryParse(indexKindToken.Value <string>(), out indexKind))
            {
                object index = null;
                switch (indexKind)
                {
                case IndexKind.Hash:
                    index = new HashIndex();
                    break;

                case IndexKind.Range:
                    index = new RangeIndex();
                    break;

                case IndexKind.Spatial:
                    index = new SpatialIndex();
                    break;

                default:
                    throw new JsonSerializationException(
                              string.Format(CultureInfo.CurrentCulture, Documents.RMResources.InvalidIndexKindValue, indexKind));
                }

                serializer.Populate(indexToken.CreateReader(), index);
                return(index);
            }
            else
            {
                throw new JsonSerializationException(
                          string.Format(CultureInfo.CurrentCulture, Documents.RMResources.InvalidIndexKindValue, indexKindToken.Value <string>()));
            }
        }