private JsonConverter CreateCovariantSearchSelector <T, TResult>(ISearchTemplateRequest originalSearchDescriptor) where T : class where TResult : class { CovariantSearch.CloseOverAutomagicCovariantResultSelector(this.Infer, originalSearchDescriptor); return(originalSearchDescriptor.TypeSelector == null ? null : new ConcreteTypeConverter <TResult>(originalSearchDescriptor.TypeSelector)); }
public ISearchResponse <TResult> SearchTemplate <T, TResult>(ISearchTemplateRequest request) where T : class where TResult : class => Dispatcher.Dispatch <ISearchTemplateRequest, SearchTemplateRequestParameters, SearchResponse <TResult> >( request, LowLevelDispatch.SearchTemplateDispatch <SearchResponse <TResult> > );
public Task <ISearchResponse <TResult> > SearchTemplateAsync <T, TResult>(ISearchTemplateRequest request) where T : class where TResult : class => this.Dispatcher.DispatchAsync <ISearchTemplateRequest, SearchTemplateRequestParameters, SearchResponse <TResult>, ISearchResponse <TResult> >( request, this.CreateSearchDeserializer <T, TResult>(request), this.LowLevelDispatch.SearchTemplateDispatchAsync <SearchResponse <TResult> > );
public Task <ISearchResponse <TResult> > SearchTemplateAsync <T, TResult>(ISearchTemplateRequest request, CancellationToken cancellationToken = default(CancellationToken)) where T : class where TResult : class => this.Dispatcher.DispatchAsync <ISearchTemplateRequest, SearchTemplateRequestParameters, SearchResponse <TResult>, ISearchResponse <TResult> >( request, cancellationToken, this.LowLevelDispatch.SearchTemplateDispatchAsync <SearchResponse <TResult> > );
public ISearchResponse <TResult> SearchTemplate <T, TResult>(ISearchTemplateRequest request) where T : class where TResult : class { var pathInfo = request .ToPathInfo(_connectionSettings) .DeserializationState(this.CreateSearchDeserializer <T, TResult>(request)); var status = this.RawDispatch.SearchTemplateDispatch <SearchResponse <TResult> >(pathInfo, request); return(status.Success ? status.Response : CreateInvalidInstance <SearchResponse <TResult> >(status)); }
/// <summary> /// Verify that the request sent to ES for a single term is being set up correctly. /// </summary> public void Check_For_Correct_Request_Data() { string term = "Breast Cancer"; ISearchTemplateRequest actualReq = null; //Setup the client with the request handler callback to be executed later. IElasticClient client = ElasticTools.GetMockedSearchTemplateClient <Suggestion>( req => actualReq = req, resMock => { //Make sure we say that the response is valid. resMock.Setup(res => res.IsValid).Returns(true); } // We don't care what the response looks like. ); IOptions <AutosuggestIndexOptions> config = GetMockedAutosuggestIndexOptions(); AutosuggestController controller = new AutosuggestController( client, config, NullLogger <AutosuggestController> .Instance ); //NOTE: this is when actualReq will get set. controller.Get( "cgov", "en", term ); SearchTemplateRequest <Suggestion> expReq = GetSearchRequest <Suggestion>( "cgov", // Search index to look in. "autosg_suggest_cgov_en", // Template name, preceded by the name of the directory it's stored in. term, // Search term 10, // Max number of records to retrieve. "\"url\", \"title\", \"metatag.description\", \"metatag.dcterms.type\"", "all" ); Assert.Equal( expReq, actualReq, new ElasticTools.SearchTemplateRequestComparer() ); }
public Task <ISearchResponse <TResult> > SearchTemplateAsync <T, TResult>(ISearchTemplateRequest request) where T : class where TResult : class { var pathInfo = request .ToPathInfo(_connectionSettings) .DeserializationState(this.CreateSearchDeserializer <T, TResult>(request)); return(this.RawDispatch.SearchTemplateDispatchAsync <SearchResponse <TResult> >(pathInfo, request) .ContinueWith <ISearchResponse <TResult> >(t => { if (t.IsFaulted) { throw t.Exception.Flatten().InnerException; } return t.Result.Success ? t.Result.Response : CreateInvalidInstance <SearchResponse <TResult> >(t.Result); })); }
private SearchResponse <TResult> FieldsSearchDeserializer <T, TResult>(IApiCallDetails response, Stream stream, ISearchTemplateRequest d) where T : class where TResult : class { var converter = this.CreateCovariantSearchSelector <T, TResult>(d); var dict = response.Success ? new NestSerializer(this.ConnectionSettings, converter).Deserialize <SearchResponse <TResult> >(stream) : null; return(dict); }
public Task <SearchResponse <T> > SearchTemplateAsync <T>(ISearchTemplateRequest request, CancellationToken ct = default) where T : class => SearchTemplateAsync <T, T>(request, ct);
public Task <ISearchResponse <T> > SearchTemplateAsync <T>(ISearchTemplateRequest request) where T : class => this.SearchTemplateAsync <T, T>(request);
public ISearchResponse <T> SearchTemplate <T>(ISearchTemplateRequest request) where T : class => this.SearchTemplate <T, T>(request);
public Task <SearchResponse <TResult> > SearchTemplateAsync <T, TResult>(ISearchTemplateRequest request, CancellationToken ct = default) where T : class where TResult : class => DoRequestAsync <ISearchTemplateRequest, SearchResponse <TResult> >(request, request.RequestParameters, ct);
private Func <IApiCallDetails, Stream, SearchResponse <TResult> > CreateSearchDeserializer <T, TResult>(ISearchTemplateRequest request) where T : class where TResult : class { Func <IApiCallDetails, Stream, SearchResponse <TResult> > responseCreator = (r, s) => this.FieldsSearchDeserializer <T, TResult>(r, s, request); return(responseCreator); }
public Task <ISearchResponse <TDocument> > SearchTemplateAsync <TDocument>(ISearchTemplateRequest request, CancellationToken ct = new CancellationToken()) where TDocument : class { throw new NotImplementedException(); }
public ISearchResponse <TDocument> SearchTemplate <TDocument>(ISearchTemplateRequest request) where TDocument : class { throw new NotImplementedException(); }
public Task <ISearchResponse <T> > SearchTemplateAsync <T>(ISearchTemplateRequest request, CancellationToken cancellationToken = default(CancellationToken)) where T : class => this.SearchTemplateAsync <T, T>(request, cancellationToken);
public SearchResponse <TResult> SearchTemplate <T, TResult>(ISearchTemplateRequest request) where T : class where TResult : class => DoRequest <ISearchTemplateRequest, SearchResponse <TResult> >(request, request.RequestParameters);
public ISearchResponse <T> SearchTemplate <T>(ISearchTemplateRequest request) where T : class { return(this.SearchTemplate <T, T>(request)); }
private SearchResponse <TResult> FieldsSearchDeserializer <T, TResult>(IElasticsearchResponse response, Stream stream, ISearchTemplateRequest d) where T : class where TResult : class { var converter = this.CreateCovariantSearchSelector <T, TResult>(d); var dict = response.Success ? Serializer.DeserializeInternal <SearchResponse <TResult> >(stream, converter) : null; return(dict); }
private SearchResponse <TResult> FieldsSearchDeserializer <T, TResult>(Stream stream, ISearchTemplateRequest d) where T : class where TResult : class { var converter = this.CreateCovariantSearchSelector <T, TResult>(d); return(this.ConnectionSettings.CreateStateful(converter).Deserialize <SearchResponse <TResult> >(stream)); }
/// <summary> /// Based on the type information present in this descriptor create method that takes /// the returned _source and hit and returns the ClrType it should deserialize too. /// This is so that Documents[A] can contain actual instances of subclasses B, C as well. /// If you specify types using .Types(typeof(B), typeof(C)) then NEST can automagically /// create a TypeSelector based on the hits _type property. /// </summary> public static void CloseOverAutomagicCovariantResultSelector(ElasticInferrer infer, ISearchTemplateRequest self) { if (infer == null || self == null) { return; } var returnType = self.ClrType; if (returnType == null) { return; } var types = (self.Types ?? Enumerable.Empty <TypeNameMarker>()).Where(t => t.Type != null).ToList(); if (self.TypeSelector != null || !types.HasAny(t => t.Type != returnType)) { return; } var typeDictionary = types.ToDictionary(infer.TypeName, t => t.Type); self.TypeSelector = (o, h) => { Type t; return(!typeDictionary.TryGetValue(h.Type, out t) ? returnType : t); }; }