Ejemplo n.º 1
0
        public async Task <V3SearchResponse> V3SearchAsync(V3SearchRequest request)
        {
            var operation = _operationBuilder.V3Search(request);

            V3SearchResponse output;

            switch (operation.Type)
            {
            case IndexOperationType.Get:
                var documentResult = await Measure.DurationWithValueAsync(
                    () => _searchIndex.Documents.GetOrNullAsync <SearchDocument.Full>(operation.DocumentKey));

                output = _responseBuilder.V3FromSearchDocument(
                    request,
                    operation.DocumentKey,
                    documentResult.Value,
                    documentResult.Duration);

                _telemetryService.TrackV3GetDocument(documentResult.Duration);
                break;

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

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

                _telemetryService.TrackV3SearchQuery(result.Duration);
                break;

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

            default:
                throw UnsupportedOperation(operation);
            }

            return(output);
        }