| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 3 | | // license information. |
| | 4 | |
|
| | 5 | | namespace Microsoft.Azure.Search.Models |
| | 6 | | { |
| | 7 | | using System.Collections.Generic; |
| | 8 | |
|
| | 9 | | public partial class FieldMappingFunction |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Creates a field mapping function that performs URL-safe Base64 encoding of the input string. Assumes that |
| | 13 | | /// the input is UTF-8 encoded. |
| | 14 | | /// </summary> |
| | 15 | | /// <remarks> |
| | 16 | | /// <para>Sample use case: Only URL-safe characters can appear in a search document key (because customers |
| | 17 | | /// must be able to address the document using the Lookup API, for example). If your data contains URL-unsafe |
| | 18 | | /// characters and you want to use it to populate a key field in your search index, use this function. |
| | 19 | | /// </para> |
| | 20 | | /// <para> |
| | 21 | | /// For details on the encoding used, see <see href="https://docs.microsoft.com/azure/search/search-indexer-fiel |
| | 22 | | /// Calling this method is the same as calling <c cref="Base64Encode(bool)"/> with <c>useHttpServerUtilityUrlTok |
| | 23 | | /// </para> |
| | 24 | | /// </remarks> |
| | 25 | | /// <returns>A new field mapping function.</returns> |
| 42 | 26 | | public static FieldMappingFunction Base64Encode() => new FieldMappingFunction("base64Encode"); |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Creates a field mapping function that performs URL-safe Base64 encoding of the input string. Assumes that |
| | 30 | | /// the input is UTF-8 encoded. |
| | 31 | | /// </summary> |
| | 32 | | /// <param name="useHttpServerUtilityUrlTokenEncode">Determines how Base64 encoding is performed. See <see href= |
| | 33 | | /// <remarks> |
| | 34 | | /// Sample use case: Only URL-safe characters can appear in a search document key (because customers |
| | 35 | | /// must be able to address the document using the Lookup API, for example). If your data contains URL-unsafe |
| | 36 | | /// characters and you want to use it to populate a key field in your search index, use this function. |
| | 37 | | /// </remarks> |
| | 38 | | /// <returns>A new field mapping function.</returns> |
| | 39 | | public static FieldMappingFunction Base64Encode(bool useHttpServerUtilityUrlTokenEncode) => |
| 2 | 40 | | new FieldMappingFunction( |
| 2 | 41 | | "base64Encode", |
| 2 | 42 | | new Dictionary<string, object> |
| 2 | 43 | | { |
| 2 | 44 | | [nameof(useHttpServerUtilityUrlTokenEncode)] = useHttpServerUtilityUrlTokenEncode |
| 2 | 45 | | }); |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Creates a field mapping function that performs a simple URL-safe encoding of the input string, |
| | 49 | | /// using UTF-8 encoding format. |
| | 50 | | /// </summary> |
| | 51 | | /// <remarks> |
| | 52 | | /// Sample use case: This field mapping function can be used as an alternative to Base64Encode if only the URL |
| | 53 | | /// unsafe characters of a key field need to be safely converted, while other characters can remain as-is. |
| | 54 | | /// </remarks> |
| | 55 | | /// <returns>A new field mapping function</returns> |
| 42 | 56 | | public static FieldMappingFunction UrlEncode() => new FieldMappingFunction("urlEncode"); |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Creates a field mapping function that performs url decoding of the input string. It assumes that the input |
| | 60 | | /// string has been url decoded with UTF-8 encoding format. |
| | 61 | | /// </summary> |
| | 62 | | /// <remarks> |
| | 63 | | /// Sample use case: Some clients that try to update blob custom metadata (which need to be ASCII-encoded) might |
| | 64 | | /// choose to URL encode the data. To ingest that custom metadata and make search meaningful, the URL decode |
| | 65 | | /// field mapping function can be used while populating the search index. |
| | 66 | | /// </remarks> |
| | 67 | | /// <returns>A new field mapping function</returns> |
| 42 | 68 | | public static FieldMappingFunction UrlDecode() => new FieldMappingFunction("urlDecode"); |
| | 69 | |
|
| | 70 | | /// <summary> |
| | 71 | | /// Creates a field mapping function that performs Base64 decoding of the input string. The input is assumed |
| | 72 | | /// to a URL-safe Base64-encoded string. |
| | 73 | | /// </summary> |
| | 74 | | /// <remarks> |
| | 75 | | /// <para>Sample use case: Blob custom metadata values must be ASCII-encoded. You can use Base64 encoding to |
| | 76 | | /// represent arbitrary Unicode strings in blob custom metadata. However, to make search meaningful, you can |
| | 77 | | /// use this function to turn the encoded data back into "regular" strings when populating your search index. |
| | 78 | | /// </para> |
| | 79 | | /// <para> |
| | 80 | | /// For details on the decoding used, see <see href="https://docs.microsoft.com/azure/search/search-indexer-fiel |
| | 81 | | /// Calling this method is the same as calling <c cref="Base64Decode(bool)"/> with <c>useHttpServerUtilityUrlTok |
| | 82 | | /// </para> |
| | 83 | | /// </remarks> |
| | 84 | | /// <returns>A new field mapping function.</returns> |
| 42 | 85 | | public static FieldMappingFunction Base64Decode() => new FieldMappingFunction("base64Decode"); |
| | 86 | |
|
| | 87 | | /// <summary> |
| | 88 | | /// Creates a field mapping function that performs Base64 decoding of the input string. The input is assumed |
| | 89 | | /// to a URL-safe Base64-encoded string. |
| | 90 | | /// </summary> |
| | 91 | | /// <param name="useHttpServerUtilityUrlTokenDecode">Determines how Base64 decoding is performed. See <see href= |
| | 92 | | /// <remarks> |
| | 93 | | /// Sample use case: Blob custom metadata values must be ASCII-encoded. You can use Base64 encoding to |
| | 94 | | /// represent arbitrary Unicode strings in blob custom metadata. However, to make search meaningful, you can |
| | 95 | | /// use this function to turn the encoded data back into "regular" strings when populating your search index. |
| | 96 | | /// </remarks> |
| | 97 | | /// <returns>A new field mapping function.</returns> |
| | 98 | | public static FieldMappingFunction Base64Decode(bool useHttpServerUtilityUrlTokenDecode) => |
| 2 | 99 | | new FieldMappingFunction( |
| 2 | 100 | | "base64Decode", |
| 2 | 101 | | new Dictionary<string, object> |
| 2 | 102 | | { |
| 2 | 103 | | [nameof(useHttpServerUtilityUrlTokenDecode)] = useHttpServerUtilityUrlTokenDecode |
| 2 | 104 | | }); |
| | 105 | |
|
| | 106 | | /// <summary> |
| | 107 | | /// Creates a field mapping function that splits a string field using the specified delimiter, and picks the |
| | 108 | | /// token at the specified position in the resulting split. |
| | 109 | | /// </summary> |
| | 110 | | /// <param name="delimiter">A string to use as the separator when splitting the input string.</param> |
| | 111 | | /// <param name="position">An integer zero-based position of the token to pick after the input string is split.< |
| | 112 | | /// <remarks> |
| | 113 | | /// <para> |
| | 114 | | /// For example, if the input is Jane Doe, the delimiter is " " (space) and the position is 0, the result is |
| | 115 | | /// Jane; if the position is 1, the result is Doe. If the position refers to a token that doesn't exist, an |
| | 116 | | /// error will be returned. |
| | 117 | | /// </para> |
| | 118 | | /// <para> |
| | 119 | | /// Sample use case: Your data source contains a PersonName field, and you want to index it as two separate |
| | 120 | | /// FirstName and LastName fields. You can use this function to split the input using the space character as |
| | 121 | | /// the delimiter. |
| | 122 | | /// </para> |
| | 123 | | /// </remarks> |
| | 124 | | /// <returns>A new field mapping function.</returns> |
| | 125 | | public static FieldMappingFunction ExtractTokenAtPosition(string delimiter, int position) => |
| 42 | 126 | | new FieldMappingFunction( |
| 42 | 127 | | "extractTokenAtPosition", |
| 42 | 128 | | new Dictionary<string, object> |
| 42 | 129 | | { |
| 42 | 130 | | [nameof(delimiter)] = delimiter, |
| 42 | 131 | | [nameof(position)] = position |
| 42 | 132 | | }); |
| | 133 | |
|
| | 134 | | /// <summary> |
| | 135 | | /// Creates a field mapping function that transforms a string formatted as a JSON array of strings into a string |
| | 136 | | /// populate a Collection(Edm.String) field in the index. |
| | 137 | | /// </summary> |
| | 138 | | /// <remarks> |
| | 139 | | /// <para> |
| | 140 | | /// For example, if the input string is ["red", "white", "blue"], then the target field of type Collection(Edm.S |
| | 141 | | /// with the three values red, white and blue. For input values that cannot be parsed as JSON string arrays, an |
| | 142 | | /// </para> |
| | 143 | | /// <para> |
| | 144 | | /// Sample use case: Azure SQL database doesn't have a built-in data type that naturally maps to Collection(Edm. |
| | 145 | | /// Search. To populate string collection fields, format your source data as a JSON string array and use this fu |
| | 146 | | /// </para> |
| | 147 | | /// </remarks> |
| | 148 | | /// <returns>A new field mapping function.</returns> |
| 42 | 149 | | public static FieldMappingFunction JsonArrayToStringCollection() => new FieldMappingFunction("jsonArrayToStringC |
| | 150 | | } |
| | 151 | | } |