예제 #1
0
        public PartialFindResult <SongForApiContract> GetList(
            string query               = "",
            string songTypes           = null,
            [FromUri] string[] tagName = null,
            [FromUri] int[] tagId      = null,
            bool childTags             = false,
            [FromUri] int[] artistId   = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks            = false,
            bool includeMembers             = false,
            bool onlyWithPvs                = false,
            [FromUri] PVServices?pvServices = null,
            int?since            = null,
            int?minScore         = null,
            int?userCollectionId = null,
            int?releaseEventId   = null,
            EntryStatus?status   = null,
            [FromUri] AdvancedSearchFilter[] advancedFilters = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule sort              = SongSortRule.Name,
            bool preferAccurateMatches     = false,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);
            var types     = EnumVal <SongType> .ParseMultiple(songTypes);

            var param = new SongQueryParams(textQuery, types, start, Math.Min(maxResults, absoluteMax), getTotalCount, sort, false, preferAccurateMatches, null)
            {
                ArtistParticipation =
                {
                    ArtistIds       = artistId,
                    Participation   = artistParticipationStatus,
                    ChildVoicebanks = childVoicebanks,
                    IncludeMembers  = includeMembers
                },
                TagIds             = tagId,
                Tags               = tagName,
                ChildTags          = childTags,
                OnlyWithPVs        = onlyWithPvs,
                TimeFilter         = since.HasValue ? TimeSpan.FromHours(since.Value) : TimeSpan.Zero,
                MinScore           = minScore ?? 0,
                PVServices         = pvServices,
                UserCollectionId   = userCollectionId ?? 0,
                ReleaseEventId     = releaseEventId ?? 0,
                AdvancedFilters    = advancedFilters,
                LanguagePreference = lang
            };

            param.Common.EntryStatus = status;

            var artists = service.Find(s => new SongForApiContract(s, null, lang, fields), param);

            return(artists);
        }
예제 #2
0
        public PartialFindResult <SongForApiContract> GetList(
            string query     = "",
            string songTypes = null,
            string tag       = null,
            int?artistId     = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks            = false,
            bool onlyWithPvs                = false,
            [FromUri] PVServices?pvServices = null,
            int?since    = null,
            int?minScore = null,
            [FromUri] ContentLanguageSelections?lyrics = null,
            int?userCollectionId           = null,
            EntryStatus?status             = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule sort              = SongSortRule.Name,
            bool preferAccurateMatches     = false,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);
            var types     = EnumVal <SongType> .ParseMultiple(songTypes);

            var param = new SongQueryParams(textQuery, types, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, sort, false, preferAccurateMatches, null)
            {
                Tag         = tag,
                OnlyWithPVs = onlyWithPvs,
                ArtistId    = artistId ?? 0,
                ArtistParticipationStatus = artistParticipationStatus,
                ChildVoicebanks           = childVoicebanks,
                TimeFilter      = since.HasValue ? TimeSpan.FromHours(since.Value) : TimeSpan.Zero,
                LyricsLanguages = lyrics != null?lyrics.Value.ToIndividualSelections().ToArray() : null,
                                      MinScore         = minScore ?? 0,
                                      PVServices       = pvServices,
                                      UserCollectionId = userCollectionId ?? 0
            };

            param.Common.EntryStatus = status;

            var artists = service.Find(s => new SongForApiContract(s, null, lang, fields), param);

            return(artists);
        }
예제 #3
0
        public ActionResult ByName(string query, ContentLanguagePreference?lang, int?start, int?maxResults, NameMatchMode?nameMatchMode,
                                   bool includeAlbums = true, bool includeArtists = true, bool includeNames = true, bool includePVs = false, bool includeTags = true, bool includeWebLinks = false,
                                   string callback    = null, DataFormat format   = DataFormat.Auto)
        {
            var textQuery = SearchTextQuery.Create(query, nameMatchMode ?? NameMatchMode.Exact);
            var param     = new SongQueryParams(textQuery, new SongType[] {}, 0, defaultMax, false, true, SongSortRule.Name, true, false, new int[] {});

            if (start.HasValue)
            {
                param.Paging.Start = start.Value;
            }

            if (maxResults.HasValue)
            {
                param.Paging.MaxEntries = Math.Min(maxResults.Value, defaultMax);
            }

            var songs = songService.Find(s => new SongForApiContract(s, null, lang ?? ContentLanguagePreference.Default, includeAlbums, includeArtists, includeNames, includePVs, includeTags, true, includeWebLinks), param);

            return(Object(songs, format, callback));
        }
예제 #4
0
        public PartialFindResult <SongForApiContract> GetList(
            string query       = "",
            SongType songTypes = SongType.Unspecified,
            string tag         = null,
            int?artistId       = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks = false,
            bool onlyWithPvs     = false,
            int?since            = null,
            [FromUri] ContentLanguageSelections?lyrics = null,
            int?userCollectionId           = null,
            EntryStatus?status             = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule sort              = SongSortRule.Name,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);
            var types = songTypes != SongType.Unspecified ? new[] { songTypes } : new SongType[0];

            var param = new SongQueryParams(query, types, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, nameMatchMode, sort, false, false, null)
            {
                Tag         = tag,
                OnlyWithPVs = onlyWithPvs,
                ArtistId    = artistId ?? 0,
                ArtistParticipationStatus = artistParticipationStatus,
                ChildVoicebanks           = childVoicebanks,
                TimeFilter      = since.HasValue ? TimeSpan.FromHours(since.Value) : TimeSpan.Zero,
                LyricsLanguages = lyrics != null?lyrics.Value.ToIndividualSelections().ToArray() : null,
                                      UserCollectionId = userCollectionId ?? 0
            };

            param.Common.EntryStatus = status;

            var artists = service.Find(s => new SongForApiContract(s, null, lang, fields), param);

            return(artists);
        }
예제 #5
0
        private ActionResult TryRedirect(string filter, EntryType searchType)
        {
            var textQuery       = SearchTextQuery.Create(filter);
            var artistTextQuery = ArtistSearchTextQuery.Create(filter);

            switch (searchType)
            {
            case EntryType.Undefined: {
                var result = entryQueries.GetList(filter, null, null, false, null, 0, 1, true, EntrySortRule.Name,
                                                  NameMatchMode.Auto, Model.DataContracts.Api.EntryOptionalFields.None, Model.Domain.Globalization.ContentLanguagePreference.Default, false, true);

                if (result.TotalCount == 1)
                {
                    var item      = result.Items.First();
                    var entryType = item.EntryType;
                    var entryId   = item.Id;

                    if (entryType == EntryType.Album)
                    {
                        return(RedirectToAlbum(entryId));
                    }

                    if (entryType == EntryType.Artist)
                    {
                        return(RedirectToArtist(entryId));
                    }

                    if (entryType == EntryType.Song)
                    {
                        return(RedirectToSong(entryId));
                    }

                    if (entryType == EntryType.Tag)
                    {
                        return(RedirectToTag(entryId, item.UrlSlug));
                    }
                }
            }
            break;

            case EntryType.Artist:
                var artist = artistService.FindArtists(new ArtistQueryParams(artistTextQuery, null, 0, 2, false, ArtistSortRule.None, false));
                if (artist.Items.Length == 1)
                {
                    return(RedirectToArtist(artist.Items[0].Id));
                }
                break;

            case EntryType.Album:
                var album = albumService.Find(new AlbumQueryParams(textQuery, DiscType.Unknown, 0, 2, false, AlbumSortRule.None, false));
                if (album.Items.Length == 1)
                {
                    return(RedirectToAlbum(album.Items[0].Id));
                }
                break;

            case EntryType.ReleaseEvent:
                var ev = eventQueries.Find(s => s.Id, textQuery, 0, null, null, 0, 2, false, EventSortRule.Name);
                if (ev.Items.Length == 1)
                {
                    return(RedirectToReleaseEvent(ev.Items[0]));
                }
                return(RedirectToAction("EventsBySeries", "Event"));

            case EntryType.Song:
                var song = songService.Find(new SongQueryParams(textQuery, null, 0, 2, false, SongSortRule.None, false, false, null));
                if (song.Items.Length == 1)
                {
                    return(RedirectToSong(song.Items[0].Id));
                }
                break;

            case EntryType.SongList:
                var list = songListQueries.Find(s => s.Id, textQuery, null, 0, 2, false, SongListSortRule.Name);
                if (list.Items.Length == 1)
                {
                    return(RedirectToSongList(list.Items[0]));
                }
                return(RedirectToAction("Featured", "SongList"));

            case EntryType.Tag:
                var tags = tagQueries.Find(new TagQueryParams(new CommonSearchParams(textQuery, true, true), PagingProperties.FirstPage(2)),
                                           TagOptionalFields.None, WebHelper.IsSSL(Request), permissionContext.LanguagePreference);
                if (tags.Items.Length == 1)
                {
                    return(RedirectToTag(tags.Items.First().Id, tags.Items.First().Name));
                }
                break;

            default: {
                var action     = "Index";
                var controller = searchType.ToString();
                return(RedirectToAction(action, controller, new { filter }));
            }
            }

            return(null);
        }
예제 #6
0
        private ActionResult TryRedirect(string filter, EntryType searchType)
        {
            var matchMode = NameMatchMode.Auto;

            filter = FindHelpers.GetMatchModeAndQueryForSearch(filter, ref matchMode);

            switch (searchType)
            {
            case EntryType.Undefined: {
                var result = services.Find(filter, 1, true);

                if (result.OnlyOneItem)
                {
                    if (result.Albums.TotalCount == 1)
                    {
                        return(RedirectToAlbum(result.Albums.Items[0].Id));
                    }

                    if (result.Artists.TotalCount == 1)
                    {
                        return(RedirectToArtist(result.Artists.Items[0].Id));
                    }

                    if (result.Songs.TotalCount == 1)
                    {
                        return(RedirectToSong(result.Songs.Items[0].Id));
                    }

                    if (result.Tags.TotalCount == 1)
                    {
                        return(RedirectToAction("Details", "Tag", new { id = result.Tags.Items[0].Name }));
                    }
                }
            }
            break;

            case EntryType.Artist:
                var artist = artistService.FindArtists(new ArtistQueryParams(filter, null, 0, 2, false, false, matchMode, ArtistSortRule.None, false));
                if (artist.Items.Length == 1)
                {
                    return(RedirectToArtist(artist.Items[0].Id));
                }
                break;

            case EntryType.Album:
                var album = albumService.Find(new AlbumQueryParams(filter, DiscType.Unknown, 0, 2, false, false, matchMode, AlbumSortRule.None, false));
                if (album.Items.Length == 1)
                {
                    return(RedirectToAlbum(album.Items[0].Id));
                }
                break;

            case EntryType.Song:
                var song = songService.Find(new SongQueryParams(filter, null, 0, 2, false, false, matchMode, SongSortRule.None, false, false, null));
                if (song.Items.Length == 1)
                {
                    return(RedirectToSong(song.Items[0].Id));
                }
                break;

            default: {
                var action     = "Index";
                var controller = searchType.ToString();
                return(RedirectToAction(action, controller, new { filter }));
            }
            }

            return(null);
        }
예제 #7
0
        private ActionResult TryRedirect(string filter, EntryType searchType)
        {
            var textQuery       = SearchTextQuery.Create(filter);
            var artistTextQuery = ArtistSearchTextQuery.Create(filter);

            switch (searchType)
            {
            case EntryType.Undefined:
            {
                var result = _entryQueries.GetList(filter, null, null, false, null, null, 0, 1, true, EntrySortRule.Name,
                                                   NameMatchMode.Auto, Model.DataContracts.Api.EntryOptionalFields.None, Model.Domain.Globalization.ContentLanguagePreference.Default,
                                                   searchTags: true, searchEvents: true);

                if (result.TotalCount == 1)
                {
                    var item    = result.Items.First();
                    var entryId = item.Id;

                    switch (item.EntryType)
                    {
                    case EntryType.Album:
                        return(RedirectToAlbum(entryId));

                    case EntryType.Artist:
                        return(RedirectToArtist(entryId));

                    case EntryType.ReleaseEvent:
                        return(RedirectToReleaseEvent(entryId, item.UrlSlug));

                    case EntryType.Song:
                        return(RedirectToSong(entryId));

                    case EntryType.Tag:
                        return(RedirectToTag(entryId, item.UrlSlug));
                    }
                }
            }
            break;

            case EntryType.Artist:
                var artist = _artistService.FindArtists(new ArtistQueryParams(artistTextQuery, null, 0, 2, false, ArtistSortRule.None, false)
                {
                    LanguagePreference = PermissionContext.LanguagePreference
                });
                if (artist.Items.Length == 1)
                {
                    return(RedirectToArtist(artist.Items[0].Id));
                }
                break;

            case EntryType.Album:
                var album = _albumService.Find(new AlbumQueryParams(textQuery, DiscType.Unknown, 0, 2, false, AlbumSortRule.None, false)
                {
                    LanguagePreference = PermissionContext.LanguagePreference
                });
                if (album.Items.Length == 1)
                {
                    return(RedirectToAlbum(album.Items[0].Id));
                }
                break;

            case EntryType.ReleaseEvent:
                var queryParams = new EventQueryParams
                {
                    TextQuery = textQuery,
                    Paging    = new PagingProperties(0, 2, false)
                };
                var ev = _eventQueries.Find(s => new { s.Id, s.UrlSlug }, queryParams);
                if (ev.Items.Length == 1)
                {
                    return(RedirectToReleaseEvent(ev.Items[0].Id, ev.Items[0].UrlSlug));
                }
                break;

            case EntryType.Song:
                var song = _songService.Find(new SongQueryParams(textQuery, null, 0, 2, false, SongSortRule.None, false, false, null)
                {
                    LanguagePreference = PermissionContext.LanguagePreference
                });
                if (song.Items.Length == 1)
                {
                    return(RedirectToSong(song.Items[0].Id));
                }
                break;

            case EntryType.SongList:
                var list = _songListQueries.Find(s => s.Id, new SongListQueryParams {
                    TextQuery = textQuery, Paging = new PagingProperties(0, 2, false), SortRule = SongListSortRule.Name
                });
                if (list.Items.Length == 1)
                {
                    return(RedirectToSongList(list.Items[0]));
                }
                return(RedirectToAction("Featured", "SongList"));

            case EntryType.Tag:
                var tags = _tagQueries.Find(new TagQueryParams(new CommonSearchParams(textQuery, true, true), PagingProperties.FirstPage(2))
                {
                    AllowChildren      = true,
                    LanguagePreference = PermissionContext.LanguagePreference
                }, TagOptionalFields.None, _permissionContext.LanguagePreference);
                if (tags.Items.Length == 1)
                {
                    return(RedirectToTag(tags.Items.First().Id, tags.Items.First().Name));
                }
                break;

            default:
            {
                var action     = "Index";
                var controller = searchType.ToString();
                return(RedirectToAction(action, controller, new { filter }));
            }
            }

            return(null);
        }