Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull swagger latest changes #11253

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sdk/search/azure-search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ Create Index using `searchIndexClient` instantiated in [Create a SearchServiceCl

<!-- embedme ./src/samples/java/com/azure/search/documents/ReadmeSamples.java#L96-L107 -->
```java
Index newIndex = new Index()
SearchIndex newIndex = new SearchIndex()
.setName("index_name")
.setFields(
Arrays.asList(new Field()
Arrays.asList(new SearchField()
.setName("Name")
.setType(DataType.EDM_STRING)
.setType(SearchFieldDataType.STRING)
.setKey(Boolean.TRUE),
new Field()
new SearchField()
.setName("Cuisine")
.setType(DataType.EDM_STRING)));
.setType(SearchFieldDataType.STRING)));
// Create index.
searchServiceClient.createIndex(newIndex);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import com.azure.search.documents.indexes.FieldIgnore;
import com.azure.search.documents.indexes.SearchableFieldProperty;
import com.azure.search.documents.indexes.SimpleFieldProperty;
import com.azure.search.documents.models.AnalyzerName;
import com.azure.search.documents.models.DataType;
import com.azure.search.documents.models.Field;
import com.azure.search.documents.models.GeoPoint;
import com.azure.search.documents.models.LexicalAnalyzerName;
import com.azure.search.documents.models.SearchField;
import com.azure.search.documents.models.SearchFieldDataType;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand All @@ -24,25 +24,25 @@
import java.util.stream.Collectors;

/**
* Helper to convert model class to Search {@link Field fields}.
* Helper to convert model class to Search {@link SearchField fields}.
*/
public final class FieldBuilder {
private static final int MAX_DEPTH = 10000;
private static final Map<Class<?>, DataType> SUPPORTED_NONE_PARAMETERIZED_TYPE = new HashMap<>();
private static final Map<Class<?>, SearchFieldDataType> SUPPORTED_NONE_PARAMETERIZED_TYPE = new HashMap<>();

static {
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Integer.class, DataType.EDM_INT32);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(int.class, DataType.EDM_INT32);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Long.class, DataType.EDM_INT64);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(long.class, DataType.EDM_INT64);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Double.class, DataType.EDM_DOUBLE);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(double.class, DataType.EDM_DOUBLE);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Boolean.class, DataType.EDM_BOOLEAN);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(boolean.class, DataType.EDM_BOOLEAN);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(String.class, DataType.EDM_STRING);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Date.class, DataType.EDM_DATE_TIME_OFFSET);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(OffsetDateTime.class, DataType.EDM_DATE_TIME_OFFSET);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(GeoPoint.class, DataType.EDM_GEOGRAPHY_POINT);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Integer.class, SearchFieldDataType.INT32);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(int.class, SearchFieldDataType.INT32);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Long.class, SearchFieldDataType.INT64);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(long.class, SearchFieldDataType.INT64);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Double.class, SearchFieldDataType.DOUBLE);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(double.class, SearchFieldDataType.DOUBLE);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Boolean.class, SearchFieldDataType.BOOLEAN);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(boolean.class, SearchFieldDataType.BOOLEAN);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(String.class, SearchFieldDataType.STRING);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(Date.class, SearchFieldDataType.DATE_TIME_OFFSET);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(OffsetDateTime.class, SearchFieldDataType.DATE_TIME_OFFSET);
SUPPORTED_NONE_PARAMETERIZED_TYPE.put(GeoPoint.class, SearchFieldDataType.GEOGRAPHY_POINT);
}

private static final List<Class<?>> UNSUPPORTED_TYPES = Arrays.asList(Byte.class,
Expand All @@ -55,13 +55,13 @@ public final class FieldBuilder {
short.class);

/**
* Creates a collection of {@link Field} objects corresponding to the properties of the type supplied.
* Creates a collection of {@link SearchField} objects corresponding to the properties of the type supplied.
*
* @param modelClass The class for which fields will be created, based on its properties.
* @param <T> The generic type of the model class.
* @return A collection of fields.
*/
public static <T> List<Field> build(Class<T> modelClass) {
public static <T> List<SearchField> build(Class<T> modelClass) {
ClientLogger logger = new ClientLogger(FieldBuilder.class);
return build(modelClass, new Stack<>(), logger);
}
Expand All @@ -72,9 +72,9 @@ public static <T> List<Field> build(Class<T> modelClass) {
* @param currentClass Current class to be built.
* @param classChain A class chain from {@code modelClass} to prior of {@code currentClass}.
* @param logger {@link ClientLogger}.
* @return A list of {@link Field} that currentClass is built to.
* @return A list of {@link SearchField} that currentClass is built to.
*/
private static List<Field> build(Class<?> currentClass, Stack<Class<?>> classChain, ClientLogger logger) {
private static List<SearchField> build(Class<?> currentClass, Stack<Class<?>> classChain, ClientLogger logger) {
if (classChain.contains(currentClass)) {
logger.warning(String.format("There is circular dependencies %s, %s", classChain, currentClass));
return null;
Expand All @@ -84,15 +84,15 @@ private static List<Field> build(Class<?> currentClass, Stack<Class<?>> classCha
"The dependency graph is too deep. Please review your schema."));
}
classChain.push(currentClass);
List<Field> searchFields = Arrays.stream(currentClass.getDeclaredFields())
List<SearchField> searchFields = Arrays.stream(currentClass.getDeclaredFields())
.filter(classField -> !classField.isAnnotationPresent(FieldIgnore.class))
.map(classField -> buildField(classField, classChain, logger))
.collect(Collectors.toList());
classChain.pop();
return searchFields;
}

private static Field buildField(java.lang.reflect.Field classField, Stack<Class<?>> classChain,
private static SearchField buildField(java.lang.reflect.Field classField, Stack<Class<?>> classChain,
ClientLogger logger) {
Type type = classField.getGenericType();

Expand All @@ -102,15 +102,15 @@ private static Field buildField(java.lang.reflect.Field classField, Stack<Class<
if (isArrayOrList(type)) {
return buildCollectionField(classField, classChain, logger);
}
List<Field> childFields = build((Class<?>) type, classChain, logger);
Field searchField = convertToBasicSearchField(classField, logger);
List<SearchField> childFields = build((Class<?>) type, classChain, logger);
SearchField searchField = convertToBasicSearchField(classField, logger);
searchField.setFields(childFields);
return searchField;
}

private static Field buildNoneParameterizedType(java.lang.reflect.Field classField,
private static SearchField buildNoneParameterizedType(java.lang.reflect.Field classField,
ClientLogger logger) {
Field searchField = convertToBasicSearchField(classField, logger);
SearchField searchField = convertToBasicSearchField(classField, logger);
return enrichWithAnnotation(searchField, classField, logger);
}

Expand All @@ -128,16 +128,16 @@ private static boolean isList(Type type) {
return List.class.isAssignableFrom((Class<?>) rawType);
}

private static Field buildCollectionField(java.lang.reflect.Field classField,
private static SearchField buildCollectionField(java.lang.reflect.Field classField,
Stack<Class<?>> classChain, ClientLogger logger) {
Type componentOrElementType = getComponentOrElementType(classField.getGenericType(), logger);
validateType(componentOrElementType, true, logger);
if (SUPPORTED_NONE_PARAMETERIZED_TYPE.containsKey(componentOrElementType)) {
Field searchField = convertToBasicSearchField(classField, logger);
SearchField searchField = convertToBasicSearchField(classField, logger);
return enrichWithAnnotation(searchField, classField, logger);
}
List<Field> childFields = build((Class<?>) componentOrElementType, classChain, logger);
Field searchField = convertToBasicSearchField(classField, logger);
List<SearchField> childFields = build((Class<?>) componentOrElementType, classChain, logger);
SearchField searchField = convertToBasicSearchField(classField, logger);
searchField.setFields(childFields);
return searchField;
}
Expand All @@ -154,11 +154,11 @@ private static Type getComponentOrElementType(Type arrayOrListType, ClientLogger
"Collection type %s is not supported.", arrayOrListType.getTypeName())));
}

private static Field convertToBasicSearchField(java.lang.reflect.Field classField,
private static SearchField convertToBasicSearchField(java.lang.reflect.Field classField,
ClientLogger logger) {
Field searchField = new Field();
SearchField searchField = new SearchField();
searchField.setName(classField.getName());
DataType dataType = covertToDataType(classField.getGenericType(), false, logger);
SearchFieldDataType dataType = covertToSearchFieldDataType(classField.getGenericType(), false, logger);
searchField.setType(dataType)
.setKey(false)
.setSearchable(false)
Expand All @@ -169,7 +169,7 @@ private static Field convertToBasicSearchField(java.lang.reflect.Field classFiel
return searchField;
}

private static Field enrichWithAnnotation(Field searchField, java.lang.reflect.Field classField,
private static SearchField enrichWithAnnotation(SearchField searchField, java.lang.reflect.Field classField,
ClientLogger logger) {
if (classField.isAnnotationPresent(SimpleFieldProperty.class)
&& classField.isAnnotationPresent(SearchableFieldProperty.class)) {
Expand All @@ -187,8 +187,8 @@ private static Field enrichWithAnnotation(Field searchField, java.lang.reflect.F
.setKey(simpleFieldPropertyAnnotation.isKey())
.setHidden(simpleFieldPropertyAnnotation.isHidden());
} else if (classField.isAnnotationPresent(SearchableFieldProperty.class)) {
if (!searchField.getType().equals(DataType.EDM_STRING)
&& !searchField.getType().equals(DataType.collection(DataType.EDM_STRING))) {
if (!searchField.getType().equals(SearchFieldDataType.STRING)
&& !searchField.getType().equals(SearchFieldDataType.collection(SearchFieldDataType.STRING))) {
throw logger.logExceptionAsError(new RuntimeException(String.format("SearchFieldProperty can only"
+ " be used on string properties. Property %s returns a %s value.",
classField.getName(), searchField.getType())));
Expand All @@ -209,13 +209,15 @@ private static Field enrichWithAnnotation(Field searchField, java.lang.reflect.F
"Please specify either analyzer or both searchAnalyzer and indexAnalyzer."));
}
if (!searchableFieldPropertyAnnotation.analyzer().isEmpty()) {
searchField.setAnalyzer(AnalyzerName.fromString((searchableFieldPropertyAnnotation.analyzer())));
searchField.setAnalyzer(LexicalAnalyzerName.fromString((searchableFieldPropertyAnnotation.analyzer())));
}
if (!searchableFieldPropertyAnnotation.searchAnalyzer().isEmpty()) {
searchField.setAnalyzer(AnalyzerName.fromString((searchableFieldPropertyAnnotation.searchAnalyzer())));
searchField.setAnalyzer(LexicalAnalyzerName.fromString(
(searchableFieldPropertyAnnotation.searchAnalyzer())));
}
if (!searchableFieldPropertyAnnotation.indexAnalyzer().isEmpty()) {
searchField.setAnalyzer(AnalyzerName.fromString((searchableFieldPropertyAnnotation.indexAnalyzer())));
searchField.setAnalyzer(LexicalAnalyzerName.fromString(
(searchableFieldPropertyAnnotation.indexAnalyzer())));
}
if (searchableFieldPropertyAnnotation.synonymMaps().length != 0) {
List<String> synonymMaps = Arrays.stream(searchableFieldPropertyAnnotation.synonymMaps())
Expand Down Expand Up @@ -248,15 +250,16 @@ private static void validateType(Type type, boolean hasArrayOrCollectionWrapped,
}
}

private static DataType covertToDataType(Type type, boolean hasArrayOrCollectionWrapped, ClientLogger logger) {
private static SearchFieldDataType covertToSearchFieldDataType(Type type, boolean hasArrayOrCollectionWrapped,
ClientLogger logger) {
validateType(type, hasArrayOrCollectionWrapped, logger);
if (SUPPORTED_NONE_PARAMETERIZED_TYPE.containsKey(type)) {
return SUPPORTED_NONE_PARAMETERIZED_TYPE.get(type);
}
if (isArrayOrList(type)) {
Type componentOrElementType = getComponentOrElementType(type, logger);
return DataType.collection(covertToDataType(componentOrElementType, true, logger));
return SearchFieldDataType.collection(covertToSearchFieldDataType(componentOrElementType, true, logger));
}
return DataType.EDM_COMPLEX_TYPE;
return SearchFieldDataType.COMPLEX;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
import com.azure.search.documents.implementation.SearchIndexRestClientImpl;
import com.azure.search.documents.implementation.models.AutocompleteRequest;
import com.azure.search.documents.implementation.models.SearchContinuationToken;
import com.azure.search.documents.implementation.models.SearchRequest;
import com.azure.search.documents.implementation.models.SuggestRequest;
import com.azure.search.documents.implementation.util.DocumentResponseConversions;
import com.azure.search.documents.implementation.util.SuggestOptionsHandler;
import com.azure.search.documents.models.IndexBatchException;
import com.azure.search.documents.models.SearchRequest;
import com.azure.search.documents.implementation.SearchIndexRestClientBuilder;
import com.azure.search.documents.implementation.SerializationUtil;
import com.azure.search.documents.models.AutocompleteOptions;
import com.azure.search.documents.models.AutocompleteRequest;
import com.azure.search.documents.models.IndexAction;
import com.azure.search.documents.models.IndexActionType;
import com.azure.search.documents.models.IndexBatchException;
import com.azure.search.documents.models.IndexDocumentsBatch;
import com.azure.search.documents.models.IndexDocumentsResult;
import com.azure.search.documents.models.RequestOptions;
import com.azure.search.documents.models.SearchOptions;
import com.azure.search.documents.models.SearchResult;
import com.azure.search.documents.models.SuggestOptions;
import com.azure.search.documents.models.SuggestRequest;
import com.azure.search.documents.models.SuggestResult;
import com.azure.search.documents.util.AutocompletePagedFlux;
import com.azure.search.documents.util.AutocompletePagedResponse;
Expand Down
Loading