Exemplo n.º 1
0
        public async Task <AutocompleteResponse> AutocompleteAsync(AutocompleteRequest request)
        {
            var operation = _operationBuilder.Autocomplete(request);

            AutocompleteResponse output;

            switch (operation.Type)
            {
            case IndexOperationType.Search:
                var result = await Measure.DurationWithValueAsync(() => _searchIndex.Documents.SearchAsync <SearchDocument.Full>(
                                                                      operation.SearchText,
                                                                      operation.SearchParameters));

                output = _responseBuilder.AutocompleteFromSearch(
                    request,
                    operation.SearchText,
                    operation.SearchParameters,
                    result.Value,
                    result.Duration);

                _telemetryService.TrackAutocompleteQuery(result.Duration);
                break;

            case IndexOperationType.Empty:
                output = _responseBuilder.EmptyAutocomplete(request);
                break;

            default:
                throw UnsupportedOperation(operation);
            }

            return(output);
        }