| | 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 Common; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// Provides factory methods for creating an index action that operates on a document. |
| | 11 | | /// </summary> |
| | 12 | | public static class IndexAction |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Creates a new IndexAction for deleting a document. |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="keyName">The name of the key field of the index.</param> |
| | 18 | | /// <param name="keyValue">The key of the document to delete.</param> |
| | 19 | | /// <returns>A new IndexAction.</returns> |
| | 20 | | public static IndexAction<Document> Delete(string keyName, string keyValue) |
| | 21 | | { |
| 6 | 22 | | Throw.IfArgumentNull(keyName, "keyName"); |
| 6 | 23 | | Throw.IfArgumentNull(keyValue, "keyValue"); |
| | 24 | |
|
| 6 | 25 | | return new IndexAction<Document>(new Document() { [keyName] = keyValue }, IndexActionType.Delete); |
| | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Creates a new IndexAction for deleting a document. |
| | 30 | | /// </summary> |
| | 31 | | /// <typeparam name="T"> |
| | 32 | | /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index. |
| | 33 | | /// </typeparam> |
| | 34 | | /// <param name="document">The document to delete; Fields other than the key are ignored.</param> |
| | 35 | | /// <returns>A new IndexAction.</returns> |
| | 36 | | public static IndexAction<T> Delete<T>(T document) |
| | 37 | | { |
| 8 | 38 | | return new IndexAction<T>(document, IndexActionType.Delete); |
| | 39 | | } |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Creates a new IndexAction for merging a document into an existing document in the index. |
| | 43 | | /// </summary> |
| | 44 | | /// <typeparam name="T"> |
| | 45 | | /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index. |
| | 46 | | /// </typeparam> |
| | 47 | | /// <param name="document">The document to merge; Set only the properties that you want to change.</param> |
| | 48 | | /// <returns>A new IndexAction.</returns> |
| | 49 | | /// <remarks> |
| | 50 | | /// <para>If type T contains non-nullable value-typed properties, these properties may not merge correctly. If y |
| | 51 | | /// do not set such a property, it will automatically take its default value (for example, 0 for int or false |
| | 52 | | /// for bool), which will override the value of the property currently stored in the index, even if this was |
| | 53 | | /// not your intent. For this reason, it is strongly recommended that you always declare value-typed |
| | 54 | | /// properties to be nullable in type T.</para> |
| | 55 | | /// <para>The above does not apply if you are using <c cref="Document">Document</c> as type T.</para> |
| | 56 | | /// </remarks> |
| | 57 | | public static IndexAction<T> Merge<T>(T document) |
| | 58 | | { |
| 18 | 59 | | return new IndexAction<T>(document, IndexActionType.Merge); |
| | 60 | | } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Creates a new IndexAction for uploading a document to the index, or merging it into an existing document |
| | 64 | | /// if it already exists in the index. |
| | 65 | | /// </summary> |
| | 66 | | /// <typeparam name="T"> |
| | 67 | | /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index. |
| | 68 | | /// </typeparam> |
| | 69 | | /// <param name="document">The document to merge or upload.</param> |
| | 70 | | /// <returns>A new IndexAction.</returns> |
| | 71 | | /// <remarks> |
| | 72 | | /// <para>If type T contains non-nullable value-typed properties, these properties may not merge correctly. If y |
| | 73 | | /// do not set such a property, it will automatically take its default value (for example, 0 for int or false |
| | 74 | | /// for bool), which will override the value of the property currently stored in the index, even if this was |
| | 75 | | /// not your intent. For this reason, it is strongly recommended that you always declare value-typed |
| | 76 | | /// properties to be nullable in type T.</para> |
| | 77 | | /// <para>The above does not apply if you are using <c cref="Document">Document</c> as type T.</para> |
| | 78 | | /// </remarks> |
| | 79 | | public static IndexAction<T> MergeOrUpload<T>(T document) |
| | 80 | | { |
| 14 | 81 | | return new IndexAction<T>(document, IndexActionType.MergeOrUpload); |
| | 82 | | } |
| | 83 | |
|
| | 84 | | /// <summary> |
| | 85 | | /// Creates a new IndexAction for uploading a document to the index. |
| | 86 | | /// </summary> |
| | 87 | | /// <typeparam name="T"> |
| | 88 | | /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index. |
| | 89 | | /// </typeparam> |
| | 90 | | /// <param name="document">The document to upload.</param> |
| | 91 | | /// <returns>A new IndexAction.</returns> |
| | 92 | | public static IndexAction<T> Upload<T>(T document) |
| | 93 | | { |
| 27558 | 94 | | return new IndexAction<T>(document, IndexActionType.Upload); |
| | 95 | | } |
| | 96 | | } |
| | 97 | | } |