| | 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.Internal |
| | 6 | | { |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Linq; |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// Compares two <c cref="SearchContinuationToken">SearchContinuationToken</c> instances for equality. |
| | 12 | | /// </summary> |
| | 13 | | /// <para> |
| | 14 | | /// This class is part of the internal implementation of the Azure Cognitive Search .NET SDK. It is not intended to |
| | 15 | | /// application code. |
| | 16 | | /// </para> |
| | 17 | | public class SearchContinuationTokenComparer : IEqualityComparer<SearchContinuationToken> |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Compares the two given continuation tokens for equality. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="first">The first continuation token to compare.</param> |
| | 23 | | /// <param name="second">The second continuation token to compare.</param> |
| | 24 | | /// <returns><c>true</c> if the two tokens are equal, <c>false</c> otherwise.</returns> |
| | 25 | | public bool Equals(SearchContinuationToken first, SearchContinuationToken second) => |
| 4 | 26 | | first?.NextLink == second?.NextLink && |
| 4 | 27 | | NextPageParametersEquals(first?.NextPageParameters, second?.NextPageParameters); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Returns a hash code for the specified object. |
| | 31 | | /// </summary> |
| | 32 | | /// <param name="obj">The object for which a hash code is to be returned.</param> |
| | 33 | | /// <returns>A hash code for the specified object.</returns> |
| 0 | 34 | | public int GetHashCode(SearchContinuationToken obj) => obj?.GetHashCode() ?? 0; |
| | 35 | |
|
| | 36 | | private static bool NextPageParametersEquals(SearchRequest first, SearchRequest second) |
| | 37 | | { |
| 4 | 38 | | if (first == null && second == null) |
| | 39 | | { |
| 2 | 40 | | return true; |
| | 41 | | } |
| | 42 | |
|
| 2 | 43 | | if ((first == null) != (second == null)) |
| | 44 | | { |
| 0 | 45 | | return false; |
| | 46 | | } |
| | 47 | |
|
| 2 | 48 | | return |
| 2 | 49 | | first.IncludeTotalResultCount == second.IncludeTotalResultCount && |
| 2 | 50 | | ((first.Facets == null && second.Facets == null) || first.Facets.SequenceEqual(second.Facets)) && |
| 2 | 51 | | first.Filter == second.Filter && |
| 2 | 52 | | first.HighlightFields == second.HighlightFields && |
| 2 | 53 | | first.HighlightPostTag == second.HighlightPostTag && |
| 2 | 54 | | first.HighlightPreTag == second.HighlightPreTag && |
| 2 | 55 | | first.MinimumCoverage == second.MinimumCoverage && |
| 2 | 56 | | first.OrderBy == second.OrderBy && |
| 2 | 57 | | first.QueryType == second.QueryType && |
| 2 | 58 | | ((first.ScoringParameters == null && second.ScoringParameters == null) || |
| 2 | 59 | | first.ScoringParameters.SequenceEqual(second.ScoringParameters)) && |
| 2 | 60 | | first.ScoringProfile == second.ScoringProfile && |
| 2 | 61 | | first.SearchText == second.SearchText && |
| 2 | 62 | | first.SearchFields == second.SearchFields && |
| 2 | 63 | | first.SearchMode == second.SearchMode && |
| 2 | 64 | | first.Select == second.Select && |
| 2 | 65 | | first.Skip == second.Skip && |
| 2 | 66 | | first.Top == second.Top; |
| | 67 | | } |
| | 68 | | } |
| | 69 | | } |