Exemple #1
0
        /// <summary>
        /// Gets the album similarity score.
        /// </summary>
        /// <param name="item1">The item1.</param>
        /// <param name="item2">The item2.</param>
        /// <returns>System.Int32.</returns>
        private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2)
        {
            var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2);

            var album1 = (MusicAlbum)item1;
            var album2 = (MusicAlbum)item2;

            var artists1 = album1.GetRecursiveChildren()
                           .OfType <Audio>()
                           .SelectMany(i =>
            {
                var list = new List <string>();

                if (!string.IsNullOrEmpty(i.AlbumArtist))
                {
                    list.Add(i.AlbumArtist);
                }
                list.AddRange(i.Artists);

                return(list);
            })
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToList();

            var artists2 = album2.GetRecursiveChildren()
                           .OfType <Audio>()
                           .SelectMany(i =>
            {
                var list = new List <string>();

                if (!string.IsNullOrEmpty(i.AlbumArtist))
                {
                    list.Add(i.AlbumArtist);
                }
                list.AddRange(i.Artists);

                return(list);
            })
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

            return(points + artists1.Where(artists2.ContainsKey).Sum(i => 5));
        }
Exemple #2
0
        /// <summary>
        /// Gets the album similarity score.
        /// </summary>
        /// <param name="item1">The item1.</param>
        /// <param name="item2">The item2.</param>
        /// <returns>System.Int32.</returns>
        private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2)
        {
            var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2);

            var album1 = (MusicAlbum)item1;
            var album2 = (MusicAlbum)item2;

            var artists1 = album1.RecursiveChildren
                           .OfType <Audio>()
                           .SelectMany(i => new[] { i.AlbumArtist, i.Artist })
                           .Where(i => !string.IsNullOrEmpty(i))
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToList();

            var artists2 = album2.RecursiveChildren
                           .OfType <Audio>()
                           .SelectMany(i => new[] { i.AlbumArtist, i.Artist })
                           .Where(i => !string.IsNullOrEmpty(i))
                           .Distinct(StringComparer.OrdinalIgnoreCase)
                           .ToList();

            return(points + artists1.Where(i => artists2.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5));
        }