コード例 #1
0
        protected string CreateMapFor(Type t)
        {
            var type   = TypeNameMarker.Create(t);
            var writer = new TypeMappingWriter(t, type, TestElasticClient.Settings, 10);

            return(writer.MapFromAttributes());
        }
コード例 #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);
        }
コード例 #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));
 }
コード例 #4
0
 public ObjectMappingDescriptor(IConnectionSettingsValues connectionSettings)
 {
     this._TypeName = TypeNameMarker.Create <TChild>();
     this._Mapping  = new ObjectMapping()
     {
     };
     this._connectionSettings = connectionSettings;
     this.Infer = new ElasticInferrer(this._connectionSettings);
 }
コード例 #5
0
        internal string GetTypeNameFor(TypeNameMarker t)
        {
            if (t == null)
            {
                return(null);
            }

            return(t.Name ?? this.GetTypeNameFor(t.Type));
        }
コード例 #6
0
        public PutMappingDescriptor <T> SetParent <K>() where K : class
        {
            var parentType = TypeNameMarker.Create <K>();

            Self.Mapping.Parent = new ParentTypeMapping()
            {
                Type = parentType
            };
            return(this);
        }
コード例 #7
0
ファイル: TypeMappingWriter.cs プロジェクト: Rustemt/NEST
        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);
        }
コード例 #8
0
ファイル: TypeMappingWriter.cs プロジェクト: piyushgiri/NEST
        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);
        }
コード例 #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");
        }
コード例 #10
0
        public void TypeNameMarkerEqualsDoesNotUseHashCode()
        {
            var collision = GetHashCollison();

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

            this.TestAddingToDictionary(typeNameMarker1, typeNameMarker2);
        }
コード例 #11
0
 public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null)
 {
     this.Indices = new [] { index };
     if (type != null)
     {
         this.Types = new[] { type }
     }
     ;
     else
     {
         this.AllTypes = true;
     }
 }
コード例 #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");
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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");
        }
コード例 #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);
        }
コード例 #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");
        }
コード例 #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);
 }
コード例 #20
0
 /// <summary>
 /// Calls putmapping on /{indices}/{type}
 /// </summary>
 public PutMappingRequest(IEnumerable <IndexNameMarker> indices, TypeNameMarker type)
 {
     this.Type    = type;
     this.Indices = indices;
 }
コード例 #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;
 }
コード例 #22
0
ファイル: Extensions.cs プロジェクト: mindis/Transformalize
 internal static bool IsNullOrEmpty(this TypeNameMarker value)
 {
     return(value == null || value.GetHashCode() == 0);
 }
コード例 #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;
        }
コード例 #24
0
 public TopChildrenQueryDescriptor()
 {
     ((ITopChildrenQuery)this).Type = TypeNameMarker.Create <T>();
 }
コード例 #25
0
 /// <summary>
 /// Calls putmapping on /_all/{type}
 /// </summary>
 public PutMappingRequest(TypeNameMarker type)
 {
     this.Type       = type;
     this.AllIndices = true;
 }
コード例 #26
0
		protected MultiFieldMapping(TypeNameMarker defaultType) : this()
		{
			_defaultType = defaultType;
		}
コード例 #27
0
 public GenericJsonOpenSearchable(IndexNameMarker index, TypeNameMarker type)
 {
     this.type = type;
     this.index = index;
 }
コード例 #28
0
 /// <summary>
 /// Calls putmapping on /{index}/{type}
 /// </summary>
 public PutMappingRequest(IndexNameMarker index, TypeNameMarker type)
 {
     this.Type    = type;
     this.Indices = new [] { index };
 }
コード例 #29
0
		public MultiFieldMapping() 
		{
			this.Fields = new Dictionary<PropertyNameMarker, IElasticCoreType>();
			_defaultType = "multi_field";
		}
コード例 #30
0
 public DocumentOptionalPathBase(IndexNameMarker indexName, TypeNameMarker typeName, string id)
 {
     this.Index = indexName;
     this.Type  = typeName;
     this.Id    = id;
 }
コード例 #31
0
 public static bool IsConditionless(this TypeNameMarker marker)
 {
     return(marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null);
 }
コード例 #32
0
 public SourceRequest(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id)
 {
 }
コード例 #33
0
 public MoreLikeThisRequest(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id)
 {
 }
コード例 #34
0
 protected DocumentPathBase(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id)
 {
 }
コード例 #35
0
 public GenericJsonOpenSearchable(IndexNameMarker index, TypeNameMarker type)
 {
     this.type  = type;
     this.index = index;
 }
コード例 #36
0
 public MultiTermVectorsRequest(IndexNameMarker index, TypeNameMarker typeNameMarker) : base(index, typeNameMarker)
 {
 }
コード例 #37
0
 public IndexTypePathBase(IndexNameMarker index, TypeNameMarker typeNameMarker)
 {
     this.Index = index;
     this.Type  = typeNameMarker;
 }