protected string CreateMapFor(Type t)
        {
            var type   = TypeNameMarker.Create(t);
            var writer = new TypeMappingWriter(t, type, TestElasticClient.Settings, 10);

            return(writer.MapFromAttributes());
        }
Exemplo n.º 2
0
        private static BulkRequest CreateIndexBulkRequest <T>(IEnumerable <T> objects, Func <T, string> getIndex, string type, Func <T, string> getParent) where T : class
        {
            var            bulkRequest    = new BulkRequest();
            TypeNameMarker typeNameMarker = type;

            bulkRequest.Type = typeNameMarker;
            var list = objects.Select(o => {
                var doc = new BulkIndexOperation <T>(o);
                if (getParent != null)
                {
                    doc.Parent = getParent(o);
                }

                if (getIndex != null)
                {
                    doc.Index = getIndex(o);
                }

                var versionedDoc = o as IVersioned;
                if (versionedDoc != null)
                {
                    doc.Version = versionedDoc.Version.ToString();
                }

                return(doc);
            }).Cast <IBulkOperation>().ToList();

            bulkRequest.Operations = list;

            return(bulkRequest);
        }
Exemplo n.º 3
0
 /// <summary>
 /// The type to execute the search on. Defaults to the inferred typename of T
 /// unless T is dynamic then a type (or AllTypes()) MUST be specified.
 /// </summary>
 public TDescriptor Type(TypeNameMarker type)
 {
     if (type == null)
     {
         return((TDescriptor)this);
     }
     return(this.Types(type));
 }
Exemplo n.º 4
0
 public ObjectMappingDescriptor(IConnectionSettingsValues connectionSettings)
 {
     this._TypeName = TypeNameMarker.Create <TChild>();
     this._Mapping  = new ObjectMapping()
     {
     };
     this._connectionSettings = connectionSettings;
     this.Infer = new ElasticInferrer(this._connectionSettings);
 }
Exemplo n.º 5
0
        internal string GetTypeNameFor(TypeNameMarker t)
        {
            if (t == null)
            {
                return(null);
            }

            return(t.Name ?? this.GetTypeNameFor(t.Type));
        }
Exemplo n.º 6
0
        public PutMappingDescriptor <T> SetParent <K>() where K : class
        {
            var parentType = TypeNameMarker.Create <K>();

            Self.Mapping.Parent = new ParentTypeMapping()
            {
                Type = parentType
            };
            return(this);
        }
Exemplo n.º 7
0
        public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettings connectionSettings, int maxRecursion)
        {
            this._type = t;
            this._connectionSettings = connectionSettings;

            this.TypeName = typeName;
            this.MaxRecursion = maxRecursion;

            this.SeenTypes = new ConcurrentDictionary<Type, int>();
            this.SeenTypes.TryAdd(t, 0);
        }
Exemplo n.º 8
0
        public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettings connectionSettings, int maxRecursion)
        {
            this._type = t;
            this._connectionSettings = connectionSettings;

            this.TypeName     = typeName;
            this.MaxRecursion = maxRecursion;

            this.SeenTypes = new ConcurrentDictionary <Type, int>();
            this.SeenTypes.TryAdd(t, 0);
        }
Exemplo n.º 9
0
        public void AttributeTypeNamesTakePrecedenceOverDefaultTypeNameInferrer()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant())
            ;

            var            inferrer = new ElasticInferrer(clientSettings);
            TypeNameMarker marker   = typeof(MyCustomAtrributeName);

            inferrer.TypeName(marker).Should().Be("custotypo");
        }
        public void TypeNameMarkerEqualsDoesNotUseHashCode()
        {
            var collision = GetHashCollison();

            var typeNameMarker1 = new TypeNameMarker {
                Name = collision.Item1
            };
            var typeNameMarker2 = new TypeNameMarker {
                Name = collision.Item2
            };

            this.TestAddingToDictionary(typeNameMarker1, typeNameMarker2);
        }
Exemplo n.º 11
0
 public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null)
 {
     this.Indices = new [] { index };
     if (type != null)
     {
         this.Types = new[] { type }
     }
     ;
     else
     {
         this.AllTypes = true;
     }
 }
Exemplo n.º 12
0
        public void MapTypeIndicesTakesPrecedenceOverAttributeName()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .MapDefaultTypeNames(dt => dt
                                                      .Add(typeof(MyCustomAtrributeName), "micutype")
                                                      )
                                 .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant())
            ;

            var            inferrer = new ElasticInferrer(clientSettings);
            TypeNameMarker marker   = typeof(MyCustomAtrributeName);

            inferrer.TypeName(marker).Should().Be("micutype");
        }
Exemplo n.º 13
0
        public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettingsValues connectionSettings, int maxRecursion)
        {
            this._type = t;
            this._connectionSettings = connectionSettings;

            this.TypeName = typeName;
            this.MaxRecursion = maxRecursion;

            this.SeenTypes = new ConcurrentDictionary<Type, int>();
            this.SeenTypes.TryAdd(t, 0);

            this._elasticSerializer = new NestSerializer(this._connectionSettings);
            this.Infer = new ElasticInferrer(this._connectionSettings);
        }
Exemplo n.º 14
0
        public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettingsValues connectionSettings, int maxRecursion)
        {
            this._type = t;
            this._connectionSettings = connectionSettings;

            this.TypeName     = typeName;
            this.MaxRecursion = maxRecursion;

            this.SeenTypes = new ConcurrentDictionary <Type, int>();
            this.SeenTypes.TryAdd(t, 0);

            this._elasticSerializer = new NestSerializer(this._connectionSettings);
            this.Infer = new ElasticInferrer(this._connectionSettings);
        }
Exemplo n.º 15
0
        public IOpenSearchableElasticType GetOpenSearchableElasticTypeByNameOrDefault(string indexName, string typeName, Dictionary <string, object> parameters = null)
        {
            var indexNameMarker = new IndexNameMarker();

            indexNameMarker.Name = indexName;
            var typeNameMarker = new TypeNameMarker();

            typeNameMarker.Name = typeName;
            IOpenSearchableElasticType type = GetOpenSearchableElasticTypeByName(indexName, typeName);

            if (type == null)
            {
                type = new GenericJsonOpenSearchable(indexName, typeName);
            }

            return(type);
        }
Exemplo n.º 16
0
        public void DefaultTypeNamesTakePrecedenceOverCustomTypeNameInferrer()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .MapDefaultTypeNames(p => p
                                                      .Add(typeof(Developer), "codemonkey")
                                                      )
                                 .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant())
            ;

            var            inferrer = new ElasticInferrer(clientSettings);
            TypeNameMarker marker   = typeof(Developer);

            inferrer.TypeName(marker).Should().Be("codemonkey");

            //Should use the custom type name inferrer that upper cases
            marker = typeof(NoopObject);
            inferrer.TypeName(marker).Should().Be("NOOPOBJECT");
        }
Exemplo n.º 17
0
        private static BulkRequest CreateIndexBulkRequest <T>(IEnumerable <T> objects, Func <T, string> getIndex, string type, Func <T, string> getParent) where T : class
        {
            if (objects == null)
            {
                throw new ArgumentNullException(nameof(objects));
            }

            var            bulkRequest    = new BulkRequest();
            TypeNameMarker typeNameMarker = type;

            bulkRequest.Type = typeNameMarker;
            var list = objects.Select(o => new BulkIndexOperation <T>(o)
            {
                Parent = getParent?.Invoke(o),
                Index  = getIndex?.Invoke(o),
            }).Cast <IBulkOperation>().ToList();

            bulkRequest.Operations = list;

            return(bulkRequest);
        }
Exemplo n.º 18
0
        public void ResolveToSepcifiedTypeNames()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .MapDefaultTypeNames(p => p
                                                      .Add(typeof(Car), "automobile")
                                                      .Add(typeof(Person), "human")
                                                      .Add(typeof(Organization), "organisation")
                                                      .Add(typeof(Developer), "codemonkey")
                                                      .Add(typeof(MyGeneric <Developer>), "codemonkey-wrapped-in-bacon")
                                                      .Add(typeof(MyGeneric <Organization>), "org-wrapped-in-bacon")
                                                      );
            var inferrer = new ElasticInferrer(clientSettings);

            TypeNameMarker marker = typeof(Car);

            inferrer.TypeName(marker).Should().Be("automobile");

            marker = typeof(Person);
            inferrer.TypeName(marker).Should().Be("human");

            marker = typeof(Organization);
            inferrer.TypeName(marker).Should().Be("organisation");

            marker = typeof(Developer);
            inferrer.TypeName(marker).Should().Be("codemonkey");

            marker = typeof(MyGeneric <Developer>);
            inferrer.TypeName(marker).Should().Be("codemonkey-wrapped-in-bacon");

            marker = typeof(MyGeneric <Organization>);
            inferrer.TypeName(marker).Should().Be("org-wrapped-in-bacon");

            //Should fall back to the default lowercase since
            //it doesn't have an explicit default
            marker = typeof(NoopObject);
            inferrer.TypeName(marker).Should().Be("noopobject");
        }
Exemplo n.º 19
0
 public IOpenSearchableElasticType GetOpenSearchableElasticTypeByName(string indexName, string typeName, Dictionary <string, object> parameters = null)
 {
     foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes(typeof(IOpenSearchableElasticType)))
     {
         IOpenSearchableElasticType etype = (IOpenSearchableElasticType)node.CreateInstance();
         if (etype.Identifier == typeName)
         {
             Type type = node.Type;
             var  ctor = type.GetConstructor(new Type[2] {
                 typeof(IndexNameMarker), typeof(TypeNameMarker)
             });
             var indexNameMarker = new IndexNameMarker();
             indexNameMarker.Name = indexName;
             var typeNameMarker = new TypeNameMarker();
             typeNameMarker.Name = typeName;
             etype = (IOpenSearchableElasticType)ctor.Invoke(new object[2] {
                 indexNameMarker, typeNameMarker
             });
             etype.Parameters = parameters;
             return(etype);
         }
     }
     return(null);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Calls putmapping on /{indices}/{type}
 /// </summary>
 public PutMappingRequest(IEnumerable <IndexNameMarker> indices, TypeNameMarker type)
 {
     this.Type    = type;
     this.Indices = indices;
 }
Exemplo n.º 21
0
 public IOpenSearchableElasticType GetOpenSearchableElasticTypeByName(string indexName, string typeName, Dictionary<string, object> parameters = null)
 {
     foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (typeof(IOpenSearchableElasticType))) {
         IOpenSearchableElasticType etype = (IOpenSearchableElasticType)node.CreateInstance();
         if (etype.Identifier == typeName) {
             Type type = node.Type;
             var ctor = type.GetConstructor(new Type[2]{ typeof(IndexNameMarker), typeof(TypeNameMarker) });
             var indexNameMarker = new IndexNameMarker();
             indexNameMarker.Name = indexName;
             var typeNameMarker = new TypeNameMarker();
             typeNameMarker.Name = typeName;
             etype = (IOpenSearchableElasticType)ctor.Invoke(new object[2]{ indexNameMarker, typeNameMarker });
             etype.Parameters = parameters;
             return etype;
         }
     }
     return null;
 }
Exemplo n.º 22
0
 internal static bool IsNullOrEmpty(this TypeNameMarker value)
 {
     return(value == null || value.GetHashCode() == 0);
 }
Exemplo n.º 23
0
        public IOpenSearchableElasticType GetOpenSearchableElasticTypeByNameOrDefault(string indexName, string typeName, Dictionary<string, object> parameters = null)
        {
            var indexNameMarker = new IndexNameMarker();
            indexNameMarker.Name = indexName;
            var typeNameMarker = new TypeNameMarker();
            typeNameMarker.Name = typeName;
            IOpenSearchableElasticType type = GetOpenSearchableElasticTypeByName(indexName, typeName);

            if (type == null) {
                type = new GenericJsonOpenSearchable(indexName, typeName);
            }

            return type;
        }
Exemplo n.º 24
0
 public TopChildrenQueryDescriptor()
 {
     ((ITopChildrenQuery)this).Type = TypeNameMarker.Create <T>();
 }
Exemplo n.º 25
0
 /// <summary>
 /// Calls putmapping on /_all/{type}
 /// </summary>
 public PutMappingRequest(TypeNameMarker type)
 {
     this.Type       = type;
     this.AllIndices = true;
 }
		protected MultiFieldMapping(TypeNameMarker defaultType) : this()
		{
			_defaultType = defaultType;
		}
 public GenericJsonOpenSearchable(IndexNameMarker index, TypeNameMarker type)
 {
     this.type = type;
     this.index = index;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Calls putmapping on /{index}/{type}
 /// </summary>
 public PutMappingRequest(IndexNameMarker index, TypeNameMarker type)
 {
     this.Type    = type;
     this.Indices = new [] { index };
 }
		public MultiFieldMapping() 
		{
			this.Fields = new Dictionary<PropertyNameMarker, IElasticCoreType>();
			_defaultType = "multi_field";
		}
Exemplo n.º 30
0
 public DocumentOptionalPathBase(IndexNameMarker indexName, TypeNameMarker typeName, string id)
 {
     this.Index = indexName;
     this.Type  = typeName;
     this.Id    = id;
 }
 public static bool IsConditionless(this TypeNameMarker marker)
 {
     return(marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null);
 }
Exemplo n.º 32
0
 public SourceRequest(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id)
 {
 }
Exemplo n.º 33
0
 public MoreLikeThisRequest(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id)
 {
 }
Exemplo n.º 34
0
 protected DocumentPathBase(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id)
 {
 }
 public GenericJsonOpenSearchable(IndexNameMarker index, TypeNameMarker type)
 {
     this.type  = type;
     this.index = index;
 }
Exemplo n.º 36
0
 public MultiTermVectorsRequest(IndexNameMarker index, TypeNameMarker typeNameMarker) : base(index, typeNameMarker)
 {
 }
 public IndexTypePathBase(IndexNameMarker index, TypeNameMarker typeNameMarker)
 {
     this.Index = index;
     this.Type  = typeNameMarker;
 }