예제 #1
0
        public TypeMappingBuilder <TEnity> WithTextIndex(Expression <Func <TEnity, object> > memberExpression, bool sparse = false, double weight = 1, string language = "english")
        {
            var names = new Dictionary <string, string>
            {
                { PropertyNameExtractor.GetPropertyName(memberExpression), "text" }
            };

            var weights = new Dictionary <string, double>
            {
                { PropertyNameExtractor.GetPropertyName(memberExpression), weight }
            };

            var indexKeys       = Newtonsoft.Json.JsonConvert.SerializeObject(names);
            var weightsDocument = BsonSerializer.Deserialize <BsonDocument>(Newtonsoft.Json.JsonConvert.SerializeObject(weights));

            Mapping.Indices.Add(new DatabaseIndexDefinition {
                Type     = typeof(TEnity),
                Keys     = indexKeys,
                Sparse   = sparse,
                Weights  = weightsDocument,
                Language = language
            });

            return(this);
        }
예제 #2
0
        public TypeMappingBuilder <TEnity> WithIndex(Expression <Func <TEnity, object> > memberExpression, bool unique = false, bool sparse = false)
        {
            var names = new Dictionary <string, int>
            {
                { PropertyNameExtractor.GetPropertyName(memberExpression), 1 }
            };

            var indexKeys = Newtonsoft.Json.JsonConvert.SerializeObject(names);

            Mapping.Indices.Add(new DatabaseIndexDefinition {
                Type   = typeof(TEnity),
                Keys   = indexKeys,
                Sparse = sparse,
                Unique = unique
            });

            return(this);
        }
예제 #3
0
        public TypeMappingBuilder <TEnity> WithTextIndex(Dictionary <Expression <Func <TEnity, object> >, double> memberExpressions, bool sparse = false, string language = "english")
        {
            var names =
                memberExpressions.Keys.Select(PropertyNameExtractor.GetPropertyName).ToDictionary(x => x, x => "text");

            var weights = memberExpressions.ToDictionary(x => PropertyNameExtractor.GetPropertyName(x.Key), x => x.Value);

            var indexKeys       = Newtonsoft.Json.JsonConvert.SerializeObject(names);
            var weightsDocument = BsonSerializer.Deserialize <BsonDocument>(Newtonsoft.Json.JsonConvert.SerializeObject(weights));

            Mapping.Indices.Add(new DatabaseIndexDefinition {
                Type     = typeof(TEnity),
                Keys     = indexKeys,
                Sparse   = sparse,
                Weights  = weightsDocument,
                Language = language
            });

            return(this);
        }
예제 #4
0
 /// <summary>
 /// If the entity has an id property with a different name than <c>Id</c>
 /// </summary>
 public TypeMappingBuilder <TEnity> WithIdProperty(Expression <Func <TEnity, string> > idProperty)
 {
     Mapping.IdMember = PropertyNameExtractor.GetPropertyName(idProperty);
     return(this);
 }