| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace MediaBrowser.Controller.Library; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Represents an item matched by a search query with its relevance score. |
| | | 7 | | /// </summary> |
| | | 8 | | public readonly struct SearchResult : IEquatable<SearchResult> |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Initializes a new instance of the <see cref="SearchResult"/> struct. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="itemId">The item ID.</param> |
| | | 14 | | /// <param name="score">The relevance score.</param> |
| | | 15 | | public SearchResult(Guid itemId, float score) |
| | | 16 | | { |
| | 0 | 17 | | ItemId = itemId; |
| | 0 | 18 | | Score = score; |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the ID of the matching item. |
| | | 23 | | /// </summary> |
| | | 24 | | public Guid ItemId { get; init; } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the relevance score. Higher values indicate more relevant results. |
| | | 28 | | /// </summary> |
| | | 29 | | public float Score { get; init; } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Compares two <see cref="SearchResult"/> instances for equality. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="left">The left operand.</param> |
| | | 35 | | /// <param name="right">The right operand.</param> |
| | | 36 | | /// <returns>True if the instances are equal; otherwise, false.</returns> |
| | | 37 | | public static bool operator ==(SearchResult left, SearchResult right) |
| | 0 | 38 | | => left.Equals(right); |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Compares two <see cref="SearchResult"/> instances for inequality. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <param name="left">The left operand.</param> |
| | | 44 | | /// <param name="right">The right operand.</param> |
| | | 45 | | /// <returns>True if the instances are not equal; otherwise, false.</returns> |
| | | 46 | | public static bool operator !=(SearchResult left, SearchResult right) |
| | 0 | 47 | | => !left.Equals(right); |
| | | 48 | | |
| | | 49 | | /// <inheritdoc/> |
| | | 50 | | public override bool Equals(object? obj) |
| | 0 | 51 | | => obj is SearchResult other && Equals(other); |
| | | 52 | | |
| | | 53 | | /// <inheritdoc/> |
| | | 54 | | public bool Equals(SearchResult other) |
| | 0 | 55 | | => ItemId.Equals(other.ItemId) && Score.Equals(other.Score); |
| | | 56 | | |
| | | 57 | | /// <inheritdoc/> |
| | | 58 | | public override int GetHashCode() |
| | 0 | 59 | | => HashCode.Combine(ItemId, Score); |
| | | 60 | | } |