Example #1
0
 /// <summary>
 /// Synchronously search using TResult as the return type
 /// </summary>
 public IQueryResponse <T> Search <T>(SearchDescriptor <T> descriptor) where T : class
 {
     return(Search <T, T>(descriptor));
 }
Example #2
0
        private IQueryResponse <TResult> GetParsedResponse <T, TResult>(ConnectionStatus status, SearchDescriptor <T> descriptor) where T : class where TResult : class
        {
            var types = (descriptor._Types ?? Enumerable.Empty <TypeNameMarker>())
                        .Where(t => t.Type != null);
            var partialFields = descriptor._PartialFields.EmptyIfNull().Select(x => x.Key);

            if (descriptor._ConcreteTypeSelector == null && (
                    types.Any(t => t.Type != typeof(TResult))) ||
                partialFields.Any())
            {
                var typeDictionary = types
                                     .ToDictionary(t => t.Resolve(this._connectionSettings), t => t.Type);

                descriptor._ConcreteTypeSelector = (o, h) =>
                {
                    Type t;
                    if (!typeDictionary.TryGetValue(h.Type, out t))
                    {
                        return(typeof(TResult));
                    }
                    return(t);
                };
            }

            if (descriptor._ConcreteTypeSelector == null)
            {
                return(this.Deserialize <QueryResponse <TResult> >(status));
            }

            return(this.Serializer.DeserializeInternal <QueryResponse <TResult> >(
                       status,
                       piggyBackJsonConverter: new ConcreteTypeConverter <TResult>(descriptor._ConcreteTypeSelector, partialFields)
                       ));
        }
Example #3
0
 /// <summary>
 /// Asynchronously search using T as the return type
 /// </summary>
 public Task <IQueryResponse <T> > SearchAsync <T>(SearchDescriptor <T> descriptor) where T : class
 {
     return(SearchAsync <T, T>(descriptor));
 }
Example #4
0
 private IQueryResponse <T> GetParsedResponse <T>(ConnectionStatus status, SearchDescriptor <T> descriptor) where T : class
 {
     return(GetParsedResponse <T, T>(status, descriptor));
 }
Example #5
0
        public IQueryResponse <TResult> DeserializeSearchResponse <T, TResult>(ConnectionStatus status, SearchDescriptor <T> originalSearchDescriptor)
            where TResult : class
            where T : class
        {
            var types = (originalSearchDescriptor._Types ?? Enumerable.Empty <TypeNameMarker>())
                        .Where(t => t.Type != null);

            if (originalSearchDescriptor._ConcreteTypeSelector == null && types.Any(t => t.Type != typeof(TResult)))
            {
                var inferrer       = new ElasticInferrer(this._settings);
                var typeDictionary = types
                                     .ToDictionary(inferrer.TypeName, t => t.Type);

                originalSearchDescriptor._ConcreteTypeSelector = (o, h) =>
                {
                    Type t;
                    if (!typeDictionary.TryGetValue(h.Type, out t))
                    {
                        return(typeof(TResult));
                    }
                    return(t);
                };
            }

            if (originalSearchDescriptor._ConcreteTypeSelector == null)
            {
                return(this.Deserialize <QueryResponse <TResult> >(status));
            }

            return(this.DeserializeInternal <QueryResponse <TResult> >(
                       status,
                       piggyBackJsonConverter: new ConcreteTypeConverter <TResult>(originalSearchDescriptor._ConcreteTypeSelector)
                       ));
        }