private async Task <SearchResult> ExecuteSearchAsync( SqlQuerySpec sqlQuerySpec, SearchOptions searchOptions, CancellationToken cancellationToken) { var feedOptions = new FeedOptions { EnableCrossPartitionQuery = true, MaxItemCount = searchOptions.MaxItemCount, RequestContinuation = searchOptions.ContinuationToken, }; if (searchOptions.CountOnly) { return(new SearchResult( (await _fhirDataStore.ExecuteDocumentQueryAsync <int>(sqlQuerySpec, feedOptions, cancellationToken)).Single(), searchOptions.UnsupportedSearchParams)); } FeedResponse <Document> fetchedResults = await _fhirDataStore.ExecuteDocumentQueryAsync <Document>(sqlQuerySpec, feedOptions, cancellationToken); FhirCosmosResourceWrapper[] wrappers = fetchedResults .Select(r => r.GetPropertyValue <FhirCosmosResourceWrapper>(SearchValueConstants.RootAliasName)).ToArray(); return(new SearchResult( wrappers, searchOptions.UnsupportedSearchParams, fetchedResults.ResponseContinuation)); }
private async Task <SearchResult> ExecuteSearchAsync( QueryDefinition sqlQuerySpec, SearchOptions searchOptions, CancellationToken cancellationToken) { var feedOptions = new QueryRequestOptions { MaxItemCount = searchOptions.MaxItemCount, }; string continuationToken = searchOptions.CountOnly ? null : searchOptions.ContinuationToken; if (searchOptions.CountOnly) { return(new SearchResult( (await _fhirDataStore.ExecuteDocumentQueryAsync <int>(sqlQuerySpec, feedOptions, continuationToken, cancellationToken)).Single(), searchOptions.UnsupportedSearchParams)); } var fetchedResults = await _fhirDataStore.ExecuteDocumentQueryAsync <FhirCosmosResourceWrapper>(sqlQuerySpec, feedOptions, continuationToken, cancellationToken); SearchResultEntry[] wrappers = fetchedResults .Select(r => new SearchResultEntry(r)).ToArray(); IReadOnlyList <(string parameterName, string reason)> unsupportedSortingParameters; if (searchOptions.Sort?.Count > 0) { unsupportedSortingParameters = searchOptions .UnsupportedSortingParams .Concat(searchOptions.Sort .Where(x => !string.Equals(x.searchParameterInfo.Name, KnownQueryParameterNames.LastUpdated, StringComparison.OrdinalIgnoreCase)) .Select(s => (s.searchParameterInfo.Name, Core.Resources.SortNotSupported))).ToList(); } else { unsupportedSortingParameters = searchOptions.UnsupportedSortingParams; } return(new SearchResult( wrappers, searchOptions.UnsupportedSearchParams, unsupportedSortingParameters, fetchedResults.ContinuationToken)); }
private async Task <SearchResult> ExecuteSearchAsync( SqlQuerySpec sqlQuerySpec, SearchOptions searchOptions, CancellationToken cancellationToken, bool calculateTotalCount = false) { var feedOptions = new FeedOptions { EnableCrossPartitionQuery = true, MaxItemCount = searchOptions.MaxItemCount, RequestContinuation = searchOptions.ContinuationToken, }; if (searchOptions.CountOnly || calculateTotalCount) { return(new SearchResult( (await _fhirDataStore.ExecuteDocumentQueryAsync <int>(sqlQuerySpec, feedOptions, cancellationToken)).Single(), searchOptions.UnsupportedSearchParams)); } FeedResponse <Document> fetchedResults = await _fhirDataStore.ExecuteDocumentQueryAsync <Document>(sqlQuerySpec, feedOptions, cancellationToken); SearchResultEntry[] wrappers = fetchedResults .Select(r => new SearchResultEntry(r.GetPropertyValue <FhirCosmosResourceWrapper>(SearchValueConstants.RootAliasName))).ToArray(); IReadOnlyList <(string parameterName, string reason)> unsupportedSortingParameters; if (searchOptions.Sort?.Count > 0) { // we don't currently support sort unsupportedSortingParameters = searchOptions.UnsupportedSortingParams.Concat(searchOptions.Sort.Select(s => (s.searchParameterInfo.Name, Core.Resources.SortNotSupported))).ToList(); } else { unsupportedSortingParameters = searchOptions.UnsupportedSortingParams; } return(new SearchResult( wrappers, searchOptions.UnsupportedSearchParams, unsupportedSortingParameters, fetchedResults.ResponseContinuation)); }