Пример #1
0
        public PartialFindResult <SongListForApiContract> GetFeaturedLists(
            string query = "",
            NameMatchMode nameMatchMode = NameMatchMode.Auto,
            SongListFeaturedCategory?featuredCategory = null,
            int start             = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongListSortRule sort = SongListSortRule.Name)
        {
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);

            return(queries.Find(s => new SongListForApiContract(s, userIconFactory, entryImagePersister, SongListOptionalFields.MainPicture),
                                textQuery, featuredCategory, start, maxResults, getTotalCount, sort));
        }
Пример #2
0
        public PartialFindResult <SongListForApiContract> GetFeaturedLists(
            string query                = "",
            [FromUri] int[] tagId       = null,
            bool childTags              = false,
            NameMatchMode nameMatchMode = NameMatchMode.Auto,
            SongListFeaturedCategory?featuredCategory = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongListSortRule sort          = SongListSortRule.Name,
            SongListOptionalFields fields  = SongListOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var textQuery   = SearchTextQuery.Create(query, nameMatchMode);
            var queryParams = new SongListQueryParams {
                TextQuery        = textQuery,
                FeaturedCategory = featuredCategory,
                Paging           = new PagingProperties(start, maxResults, getTotalCount),
                SortRule         = sort,
                TagIds           = tagId,
                ChildTags        = childTags
            };

            return(queries.Find(s => new SongListForApiContract(s, lang, userIconFactory, entryImagePersister, fields), queryParams));
        }
Пример #3
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);
        }
Пример #4
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);
        }