Example #1
0
        private IEnumerable <SongRecommendationDto> GetSimilar(SongDetailsDto currentSong, string userId, int maxCount)
        {
            var songRecommendations = _graphClient.Cypher
                                      .Match("(song:Song)-[CATEGORIZED_BY]->(songCategory:SongCategory)")
                                      .Where((SongCategory songCategory) => songCategory.Id == currentSong.SongCategory.Id)
                                      .AndWhere((Song song) => song.Id != currentSong.Song.Id)
                                      .Match("(song)-[COMPOSED_BY]->(artist:Artist)")
                                      .Match("(targetSong:Song)")
                                      .Where((Song targetSong) => targetSong.Id == currentSong.Song.Id)
                                      .OptionalMatch("(song)-[ri:CONTAINS]->(instrument:Instrument)<-[:CONTAINS]-(targetSong)")
                                      .OptionalMatch("(song)-[rt:DESCRIBED_BY]->(tag:Tag)<-[:DESCRIBED_BY]-(targetSong)")
                                      .OptionalMatch("(user:User)-[LIKES]->(song)")
                                      .Where((User user) => user.Id != userId)
                                      .ReturnDistinct((song, artist, instrument, tag, user) => new SongRecommendationDto
            {
                Song              = song.As <Song>(),
                Artist            = artist.As <Artist>(),
                CommonInstruments = instrument.CountDistinct(),
                CommonTags        = tag.CountDistinct(),
                NumberOfLikes     = user.Count()
            })
                                      .Results
                                      .OrderByDescending(ComputeRecommendationScore)
                                      .Take(maxCount);

            return(songRecommendations);
        }
Example #2
0
        public static SongItemModel ToSongItemModel(SongDetailsDto songDetails)
        {
            if (songDetails == null)
            {
                return(null);
            }

            return(new SongItemModel
            {
                Id = songDetails.Song.Id,
                Name = songDetails.Song.Title,
                Artist = ArtistMapper.ToArtistModel(songDetails.Artist)
            });
        }
Example #3
0
        public static SongModel ToSongModel(SongDetailsDto songDetails)
        {
            if (songDetails == null)
            {
                return(null);
            }

            return(new SongModel
            {
                Id = songDetails.Song.Id,
                Name = songDetails.Song.Title,
                Url = songDetails.Song.Url,
                Artist = ArtistMapper.ToArtistModel(songDetails.Artist),
                SongCategory = SongCategoryMapper.ToSongCategoryModel(songDetails.SongCategory),
                //TODO: Have a look over here
                Tags = songDetails.Tags.GroupBy(t => t.Id).Select(grp => TagMapper.ToTagModel(grp.FirstOrDefault())),
                Instruments = songDetails.Instruments.GroupBy(i => i.Id).Select(grp => InstrumentMapper.ToInstrumentModel(grp.FirstOrDefault()))
            });
        }