Skip to content

Commit

Permalink
Search Regeneration (#34943)
Browse files Browse the repository at this point in the history
Search Swagger Regeneration
  • Loading branch information
jairmyree committed Jun 26, 2023
1 parent 1865f1d commit 1bf98f0
Show file tree
Hide file tree
Showing 45 changed files with 2,309 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ private Mono<SearchPagedResponse> search(SearchRequest request, String continuat
SearchPagedResponse page = new SearchPagedResponse(
new SimpleResponse<>(response, getSearchResults(result, serializer)),
createContinuationToken(result, serviceVersion), result.getFacets(), result.getCount(),
result.getCoverage(), result.getAnswers());
result.getCoverage(), result.getAnswers(), result.getSemanticPartialResponseReason(),
result.getSemanticPartialResponseType());
if (continuationToken == null) {
firstPageResponseWrapper.setFirstPageResponse(page);
}
Expand Down Expand Up @@ -1077,19 +1078,24 @@ static SearchRequest createSearchRequest(String searchText, SearchOptions option
static String createSearchRequestAnswers(SearchOptions searchOptions) {
QueryAnswerType answer = searchOptions.getAnswers();
Integer answersCount = searchOptions.getAnswersCount();
Double answerThreshold = searchOptions.getAnswerThreshold();

// No answer has been defined.
if (answer == null) {
return null;
}

// No count, just send the QueryAnswer.
if (answersCount == null) {
return answer.toString();
}
String answerString = answer.toString();

// Answer and count, format it as the service expects.
return answer + "|count-" + answersCount;
if (answersCount != null && answerThreshold != null) {
return answerString + "|count-" + answersCount + ",threshold-" + answerThreshold;
} else if (answersCount != null && answerThreshold == null) {
return answerString + "|count-" + answersCount;
} else if (answersCount == null && answerThreshold != null) {
return answerString + "|threshold-" + answerThreshold;
} else {
return answerString;
}
}

static String createSearchRequestCaptions(SearchOptions searchOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.azure.search.documents.util.SuggestPagedResponse;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -618,7 +619,7 @@ public <T> Response<T> getDocumentWithResponse(String key, Class<T> modelClass,
Context context) {

try {
Response<Object> response = restClient.getDocuments()
Response<Map<String, Object>> response = restClient.getDocuments()
.getWithResponse(key, selectedFields, null, Utility.enableSyncRestProxy(context));

return new SimpleResponse<>(response, serializer.deserializeFromBytes(
Expand Down Expand Up @@ -778,7 +779,8 @@ private SearchPagedResponse search(SearchRequest request, String continuationTok
SearchPagedResponse page = new SearchPagedResponse(
new SimpleResponse<>(response, getSearchResults(result, serializer)),
createContinuationToken(result, serviceVersion), result.getFacets(), result.getCount(),
result.getCoverage(), result.getAnswers());
result.getCoverage(), result.getAnswers(), result.getSemanticPartialResponseReason(),
result.getSemanticPartialResponseType());
if (continuationToken == null) {
firstPageResponseWrapper.setFirstPageResponse(page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
import com.azure.search.documents.models.AutocompleteMode;
import com.azure.search.documents.models.AutocompleteResult;
import com.azure.search.documents.models.IndexDocumentsResult;
import com.azure.search.documents.models.QueryDebugMode;
import com.azure.search.documents.models.QueryLanguage;
import com.azure.search.documents.models.QuerySpellerType;
import com.azure.search.documents.models.QueryType;
import com.azure.search.documents.models.ScoringStatistics;
import com.azure.search.documents.models.SearchMode;
import com.azure.search.documents.models.SemanticErrorHandling;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -113,6 +116,9 @@ Mono<Response<SearchDocumentsResult>> searchGet(
@QueryParam(value = "scoringParameter", multipleQueryParams = true) List<String> scoringParameters,
@QueryParam("scoringProfile") String scoringProfile,
@QueryParam("semanticConfiguration") String semanticConfiguration,
@QueryParam("semanticErrorHandling") SemanticErrorHandling semanticErrorHandling,
@QueryParam("semanticMaxWaitInMilliseconds") Integer semanticMaxWaitInMilliseconds,
@QueryParam("debug") QueryDebugMode debug,
@QueryParam("searchFields") String searchFields,
@QueryParam("queryLanguage") QueryLanguage queryLanguage,
@QueryParam("speller") QuerySpellerType speller,
Expand Down Expand Up @@ -149,6 +155,9 @@ Response<SearchDocumentsResult> searchGetSync(
@QueryParam(value = "scoringParameter", multipleQueryParams = true) List<String> scoringParameters,
@QueryParam("scoringProfile") String scoringProfile,
@QueryParam("semanticConfiguration") String semanticConfiguration,
@QueryParam("semanticErrorHandling") SemanticErrorHandling semanticErrorHandling,
@QueryParam("semanticMaxWaitInMilliseconds") Integer semanticMaxWaitInMilliseconds,
@QueryParam("debug") QueryDebugMode debug,
@QueryParam("searchFields") String searchFields,
@QueryParam("queryLanguage") QueryLanguage queryLanguage,
@QueryParam("speller") QuerySpellerType speller,
Expand Down Expand Up @@ -193,7 +202,7 @@ Response<SearchDocumentsResult> searchPostSync(
@Get("/docs('{key}')")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(SearchErrorException.class)
Mono<Response<Object>> get(
Mono<Response<Map<String, Object>>> get(
@HostParam("endpoint") String endpoint,
@HostParam("indexName") String indexName,
@PathParam("key") String key,
Expand All @@ -206,7 +215,7 @@ Mono<Response<Object>> get(
@Get("/docs('{key}')")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(SearchErrorException.class)
Response<Object> getSync(
Response<Map<String, Object>> getSync(
@HostParam("endpoint") String endpoint,
@HostParam("indexName") String indexName,
@PathParam("key") String key,
Expand Down Expand Up @@ -652,10 +661,11 @@ public SearchDocumentsResult searchPost(SearchRequest searchRequest, RequestOpti
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws SearchErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return any object along with {@link Response} on successful completion of {@link Mono}.
* @return a document retrieved via a document lookup operation along with {@link Response} on successful completion
* of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Object>> getWithResponseAsync(
public Mono<Response<Map<String, Object>>> getWithResponseAsync(
String key, List<String> selectedFields, RequestOptions requestOptions) {
final String accept = "application/json; odata.metadata=none";
UUID xMsClientRequestIdInternal = null;
Expand Down Expand Up @@ -693,10 +703,11 @@ public Mono<Response<Object>> getWithResponseAsync(
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws SearchErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return any object along with {@link Response} on successful completion of {@link Mono}.
* @return a document retrieved via a document lookup operation along with {@link Response} on successful completion
* of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Object>> getWithResponseAsync(
public Mono<Response<Map<String, Object>>> getWithResponseAsync(
String key, List<String> selectedFields, RequestOptions requestOptions, Context context) {
final String accept = "application/json; odata.metadata=none";
UUID xMsClientRequestIdInternal = null;
Expand Down Expand Up @@ -731,10 +742,10 @@ public Mono<Response<Object>> getWithResponseAsync(
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws SearchErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return any object on successful completion of {@link Mono}.
* @return a document retrieved via a document lookup operation on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Object> getAsync(String key, List<String> selectedFields, RequestOptions requestOptions) {
public Mono<Map<String, Object>> getAsync(String key, List<String> selectedFields, RequestOptions requestOptions) {
return getWithResponseAsync(key, selectedFields, requestOptions)
.flatMap(res -> Mono.justOrEmpty(res.getValue()));
}
Expand All @@ -750,10 +761,10 @@ public Mono<Object> getAsync(String key, List<String> selectedFields, RequestOpt
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws SearchErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return any object on successful completion of {@link Mono}.
* @return a document retrieved via a document lookup operation on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Object> getAsync(
public Mono<Map<String, Object>> getAsync(
String key, List<String> selectedFields, RequestOptions requestOptions, Context context) {
return getWithResponseAsync(key, selectedFields, requestOptions, context)
.flatMap(res -> Mono.justOrEmpty(res.getValue()));
Expand All @@ -770,10 +781,10 @@ public Mono<Object> getAsync(
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws SearchErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return any object along with {@link Response}.
* @return a document retrieved via a document lookup operation along with {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Object> getWithResponse(
public Response<Map<String, Object>> getWithResponse(
String key, List<String> selectedFields, RequestOptions requestOptions, Context context) {
final String accept = "application/json; odata.metadata=none";
UUID xMsClientRequestIdInternal = null;
Expand Down Expand Up @@ -808,10 +819,10 @@ public Response<Object> getWithResponse(
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws SearchErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return any object.
* @return a document retrieved via a document lookup operation.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Object get(String key, List<String> selectedFields, RequestOptions requestOptions) {
public Map<String, Object> get(String key, List<String> selectedFields, RequestOptions requestOptions) {
return getWithResponse(key, selectedFields, requestOptions, Context.NONE).getValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static SearchResult map(com.azure.search.documents.implementation.models.
SearchResultHelper.setCaptions(searchResult, obj.getCaptions());
SearchResultHelper.setAdditionalProperties(searchResult, new SearchDocument(obj.getAdditionalProperties()));
SearchResultHelper.setJsonSerializer(searchResult, (JsonSerializer) serializer);

SearchResultHelper.setDocumentDebugInfo(searchResult, obj.getDocumentDebugInfo());
return searchResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.util.serializer.JsonSerializer;
import com.azure.search.documents.SearchDocument;
import com.azure.search.documents.models.CaptionResult;
import com.azure.search.documents.models.DocumentDebugInfo;
import com.azure.search.documents.models.SearchResult;

import java.util.List;
Expand All @@ -28,6 +29,7 @@ public interface SearchResultAccessor {
void setJsonSerializer(SearchResult searchResult, JsonSerializer jsonSerializer);
void setRerankerScore(SearchResult searchResult, Double rerankerScore);
void setCaptions(SearchResult searchResult, List<CaptionResult> captions);
void setDocumentDebugInfo(SearchResult searchResult, List<DocumentDebugInfo> documentDebugInfo);
}

/**
Expand Down Expand Up @@ -58,4 +60,8 @@ static void setRerankerScore(SearchResult searchResult, Double rerankerScore) {
static void setCaptions(SearchResult searchResult, List<CaptionResult> captions) {
accessor.setCaptions(searchResult, captions);
}

static void setDocumentDebugInfo(SearchResult searchResult, List<DocumentDebugInfo> documentDebugInfo) {
accessor.setDocumentDebugInfo(searchResult, documentDebugInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package com.azure.search.documents.implementation.models;

import com.azure.core.util.ExpandableStringEnum;
import java.util.Collection;

/** The way the field was used for the semantic enrichment process. */
public final class QueryResultDocumentSemanticFieldState
extends ExpandableStringEnum<QueryResultDocumentSemanticFieldState> {
/** The field was fully used for semantic enrichment. */
public static final QueryResultDocumentSemanticFieldState USED = fromString("used");

/** The field was not used for semantic enrichment. */
public static final QueryResultDocumentSemanticFieldState UNUSED = fromString("unused");

/** The field was partially used for semantic enrichment. */
public static final QueryResultDocumentSemanticFieldState PARTIAL = fromString("partial");

/**
* Creates a new instance of QueryResultDocumentSemanticFieldState value.
*
* @deprecated Use the {@link #fromString(String)} factory method.
*/
@Deprecated
public QueryResultDocumentSemanticFieldState() {}

/**
* Creates or finds a QueryResultDocumentSemanticFieldState from its string representation.
*
* @param name a name to look for.
* @return the corresponding QueryResultDocumentSemanticFieldState.
*/
public static QueryResultDocumentSemanticFieldState fromString(String name) {
return fromString(name, QueryResultDocumentSemanticFieldState.class);
}

/**
* Gets known QueryResultDocumentSemanticFieldState values.
*
* @return known QueryResultDocumentSemanticFieldState values.
*/
public static Collection<QueryResultDocumentSemanticFieldState> values() {
return values(QueryResultDocumentSemanticFieldState.class);
}
}
Loading

0 comments on commit 1bf98f0

Please sign in to comment.