Пример #1
0
        private async Task <V2SearchResponse> UseSearchIndexAsync(V2SearchRequest request)
        {
            var operation = _operationBuilder.V2SearchWithSearchIndex(request);

            V2SearchResponse output;

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

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

                _telemetryService.TrackV2GetDocumentWithSearchIndex(documentResult.Duration);
                break;

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

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

                _telemetryService.TrackV2SearchQueryWithSearchIndex(result.Duration);
                break;

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

            default:
                throw UnsupportedOperation(operation);
            }

            return(output);
        }