public async Task <PartialCollectionModel <SearchableProduct> > SearchProducts(SearchArgs searchArgs) { var fieldsToSearch = new Collection <TextSearchField <ProductIndexItem> > { new() { Field = field => field.ProductName }, new() { Path = path => path.Supplier, Field = field => field.Supplier.CompanyName }, new() { Path = path => path.Category, Field = field => field.Category.CategoryName } }; var filters = _searchFiltersService.CreateFilters(searchArgs); var request = await ElasticSearchRequest <ProductIndexItem> .Init(_elasticSearchService) .Pipe(searchRequest => searchRequest.CreateSearchRequestQuery(searchArgs, fieldsToSearch, filters)) .CreateSort(searchArgs) .PipeAsync(async searchRequest => await searchRequest.BuildAsync()); var response = await _elasticSearchService.SearchAsync(request); var products = response.SearchResults.Documents; return(new PartialCollectionModel <SearchableProduct> { Values = _mapper.Map <IReadOnlyCollection <SearchableProduct> >(products), Count = response.SearchResults.Total, Offset = searchArgs.Offset + 1, Limit = response.SearchResults.Hits.Count }); } }
public async Task <IList <SearchableSupplier> > GetSuppliers(SearchArgs searchArgs) { var fieldsToSearch = new Collection <TextSearchField <SupplierIndexItem> > { new() { Field = field => field.CompanyName } }; var request = await ElasticSearchRequest <SupplierIndexItem> .Init(_elasticSearchService) .CreateSearchRequestQuery(searchArgs, fieldsToSearch) .CreateSort(searchArgs) .PipeAsync(async searchRequest => await searchRequest.BuildAsync()); var response = await _elasticSearchService.SearchAsync(request); var suppliers = response.SearchResults.Documents; var dtos = _mapper.Map <IList <SearchableSupplier> >(suppliers); return(dtos); }