Beispiel #1
0
        private IQueryable <Album> CreateQuery(
            AlbumQueryParams queryParams,
            ParsedAlbumQuery parsedQuery,
            NameMatchMode?nameMatchMode = null)
        {
            var artistIds = EntryIdsCollection.CreateWithFallback(queryParams.ArtistParticipation.ArtistIds.Ids, parsedQuery.ArtistId);
            var textQuery = SearchTextQuery.Create(parsedQuery.Name, nameMatchMode ?? queryParams.Common.NameMatchMode);

            var query = Query <Album>()
                        .WhereIsDeleted(queryParams.Deleted)
                        .WhereHasName(textQuery, allowCatNum: true)
                        .WhereStatusIs(queryParams.Common.EntryStatus)
                        .WhereHasArtistParticipationStatus(queryParams.ArtistParticipation, artistIds, querySource.OfType <Artist>())
                        .WhereHasBarcode(queryParams.Barcode)
                        .WhereHasType(queryParams.AlbumType)
                        .WhereHasTags(queryParams.TagIds, queryParams.ChildTags)
                        .WhereHasTags(queryParams.Tags)
                        .WhereHasTag(parsedQuery.TagName)
                        .WhereReleaseDateIsAfter(queryParams.ReleaseDateAfter)
                        .WhereReleaseDateIsBefore(queryParams.ReleaseDateBefore)
                        .WhereSortBy(queryParams.SortRule)
                        .WhereMatchFilters(queryParams.AdvancedFilters);

            return(query);
        }
        public ActionResult Index(string query, DiscType discType = DiscType.Unknown,
            int start = 0, bool getTotalCount = false, AlbumSortRule sort = AlbumSortRule.Name,
            NameMatchMode nameMatchMode = NameMatchMode.Exact, DataFormat format = DataFormat.Auto)
        {
            var queryParams = new AlbumQueryParams(query, discType, start, maxResults, false, getTotalCount, nameMatchMode, sort);

            var entries = Service.Find(a => new AlbumForApiContract(a, LoginManager.LanguagePreference), queryParams);

            return Object(entries, format);
        }
Beispiel #3
0
        /// <summary>
        /// Get albums, searching by exact matches FIRST.
        /// This mode does not support paging.
        /// </summary>
        private PartialFindResult <Album> GetAlbumsMoveExactToTop(AlbumQueryParams queryParams, ParsedAlbumQuery parsedQuery)
        {
            var sortRule   = queryParams.SortRule;
            var maxResults = queryParams.Paging.MaxEntries;
            var getCount   = queryParams.Paging.GetTotalCount;

            // Exact query contains the "exact" matches.
            // Note: the matched name does not have to be in user's display language, it can be any name.
            // The songs are sorted by user's display language though
            var exactQ = CreateQuery(queryParams, parsedQuery, NameMatchMode.StartsWith);

            int count;

            int[] ids;
            var   exactResults = exactQ
                                 .OrderBy(sortRule, LanguagePreference)
                                 .Select(s => s.Id)
                                 .Take(maxResults)
                                 .ToArray();

            if (exactResults.Length >= maxResults)
            {
                ids   = exactResults;
                count = getCount ? CreateQuery(queryParams, parsedQuery).Count() : 0;
            }
            else
            {
                var directQ = CreateQuery(queryParams, parsedQuery);

                var direct = directQ
                             .OrderBy(sortRule, LanguagePreference)
                             .Select(s => s.Id)
                             .Take(maxResults)
                             .ToArray();

                ids = exactResults
                      .Concat(direct)
                      .Distinct()
                      .Take(maxResults)
                      .ToArray();

                count = getCount ? directQ.Count() : 0;
            }

            var albums = SortByIds(
                querySource
                .Query <Album>()
                .Where(s => ids.Contains(s.Id))
                .ToArray(), ids);

            return(new PartialFindResult <Album>(albums, count, queryParams.Common.Query, true));
        }
        public ActionResult Index(string query, DiscType discType = DiscType.Unknown,
            int start = 0, bool getTotalCount = false, AlbumSortRule sort = AlbumSortRule.Name,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            bool includeArtists = true, bool includeNames = true, bool includePVs = false, bool includeTags = true, bool includeWebLinks = false,
            DataFormat format = DataFormat.Auto,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var queryParams = new AlbumQueryParams(query, discType, start, maxResults, false, getTotalCount, nameMatchMode, sort);

            var entries = Service.Find(a => new AlbumForApiContract(a, null, lang, includeArtists, includeNames, includePVs, includeTags, includeWebLinks), queryParams);

            return Object(entries, format);
        }
Beispiel #5
0
        private PartialFindResult <Album> GetAlbums(AlbumQueryParams queryParams, ParsedAlbumQuery parsedQuery)
        {
            var query = CreateQuery(queryParams, parsedQuery);

            var ids = query
                      .OrderBy(queryParams.SortRule, LanguagePreference)
                      .Select(s => s.Id)
                      .Paged(queryParams.Paging)
                      .ToArray();

            var albums = SortByIds(querySource
                                   .Query <Album>()
                                   .Where(s => ids.Contains(s.Id))
                                   .ToArray(), ids);

            var count = (queryParams.Paging.GetTotalCount ? query.Count() : 0);

            return(new PartialFindResult <Album>(albums, count, queryParams.Common.Query, false));
        }
Beispiel #6
0
        private IQueryable <Album> CreateQuery(
            AlbumQueryParams queryParams,
            ParsedAlbumQuery parsedQuery,
            NameMatchMode?nameMatchMode = null)
        {
            var artistId = queryParams.ArtistId != 0 ? queryParams.ArtistId : parsedQuery.ArtistId;

            var query = Query <Album>()
                        .Where(s => !s.Deleted)
                        .WhereHasName(parsedQuery.Name, nameMatchMode ?? queryParams.Common.NameMatchMode, allowCatNum: true)
                        .WhereDraftsOnly(queryParams.Common.DraftOnly)
                        .WhereStatusIs(queryParams.Common.EntryStatus)
                        .WhereHasArtistParticipationStatus(artistId, queryParams.ArtistParticipationStatus, queryParams.ChildVoicebanks, id => querySource.Load <Artist>(id))
                        .WhereHasBarcode(queryParams.Barcode)
                        .WhereHasType(queryParams.AlbumType)
                        .WhereHasTag(!string.IsNullOrEmpty(queryParams.Tag) ? queryParams.Tag : parsedQuery.TagName);

            return(query);
        }
Beispiel #7
0
        public PartialFindResult <Album> Find(AlbumQueryParams queryParams)
        {
            var query       = queryParams.Common.Query ?? string.Empty;
            var parsedQuery = ParseTextQuery(query);

            var isMoveToTopQuery = (queryParams.Common.MoveExactToTop &&
                                    queryParams.Common.NameMatchMode != NameMatchMode.StartsWith &&
                                    queryParams.Common.NameMatchMode != NameMatchMode.Exact &&
                                    queryParams.ArtistId == 0 &&
                                    queryParams.Paging.Start == 0 &&
                                    parsedQuery.HasNameQuery);

            if (isMoveToTopQuery)
            {
                return(GetAlbumsMoveExactToTop(queryParams, parsedQuery));
            }

            return(GetAlbums(queryParams, parsedQuery));
        }
		public void SetUp() {

			querySource = new QuerySourceList();

			artist = new Artist(TranslatedString.Create("XenonP")) { Id = 64 };
			querySource.Add(artist);

			album = new Album(new LocalizedString("Synthesis", ContentLanguageSelection.English)) { Id = 1, DiscType = DiscType.Album, CreateDate = new DateTime(2011, 1, 16) };
			AddAlbum(album);

			albumWithArtist = new Album(new LocalizedString("DIVINE", ContentLanguageSelection.English)) { Id = 1010, DiscType = DiscType.Unknown, RatingAverage = 4.5, CreateDate = new DateTime(2012, 1, 15) };
			albumWithArtist.AddArtist(artist);
			AddAlbum(albumWithArtist);

			queryParams = new AlbumQueryParams();

			search = new Model.Service.Search.AlbumSearch.AlbumSearch(querySource, ContentLanguagePreference.Default);

		}
        public PartialViewResult AlbumsPaged(int id, ArtistAlbumParticipationStatus? artistParticipation, int? page)
        {
            var pageIndex = (page - 1) ?? 0;
            var queryParams = new AlbumQueryParams {
                Paging = PagingProperties.CreateFromPage(pageIndex, entriesPerPage, true),
                SortRule = AlbumSortRule.ReleaseDateWithNulls,
                ArtistId = id,
                ArtistParticipationStatus = artistParticipation ?? ArtistAlbumParticipationStatus.Everything
            };

            var result = Services.Albums.Find(queryParams);

            var target = queryParams.ArtistParticipationStatus == ArtistAlbumParticipationStatus.OnlyCollaborations ? "ui-tabs-3" : "ui-tabs-2";
            var data = new PagingData<AlbumContract>(result.Items.ToPagedList(pageIndex, entriesPerPage, result.TotalCount), id, "AlbumsPaged", target);
            data.RouteValues = new RouteValueDictionary(new { artistParticipation });

            return PartialView("PagedAlbums", data);
        }
Beispiel #10
0
        public PartialViewResult AlbumsPaged(int id, int? page)
        {
            var pageIndex = (page - 1) ?? 0;
            var queryParams = new AlbumQueryParams {
                Paging = PagingProperties.CreateFromPage(pageIndex, entriesPerPage, true),
                SortRule = AlbumSortRule.Name,
                ArtistId = id
            };
            var result = Services.Albums.Find(queryParams);
            var data = new PagingData<AlbumContract>(result.Items.ToPagedList(pageIndex, entriesPerPage, result.TotalCount), id, "AlbumsPaged", "ui-tabs-2");

            return PartialView("PagedAlbums", data);
        }
        public PartialFindResult<AlbumForApiContract> GetList(
            string query = "",
            DiscType discTypes = DiscType.Unknown,
            string tag = null,
            int? artistId = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks = false,
            string barcode = null,
            EntryStatus? status = null,
            int start = 0,
            int maxResults = defaultMax,
            bool getTotalCount = false,
            AlbumSortRule? sort = null,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            AlbumOptionalFields fields = AlbumOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);

            var queryParams = new AlbumQueryParams(query, discTypes, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, nameMatchMode, sort ?? AlbumSortRule.Name) {
                Tag = tag,
                ArtistId = artistId ?? 0,
                ArtistParticipationStatus = artistParticipationStatus,
                ChildVoicebanks = childVoicebanks,
                Barcode = barcode
            };
            queryParams.Common.EntryStatus = status;

            var ssl = WebHelper.IsSSL(Request);

            var entries = service.Find(a => new AlbumForApiContract(a, null, lang, thumbPersister, ssl, fields), queryParams);

            return entries;
        }
Beispiel #12
0
        public int GetAlbumCount(
            AlbumQueryParams queryParams, string query, DiscType discType, bool draftsOnly, NameMatchMode nameMatchMode, AlbumSortRule sortRule)
        {
            query = query ?? string.Empty;

            if (queryParams.ArtistId == 0 && string.IsNullOrWhiteSpace(query))
            {
                var albumQ = Query <Album>()
                             .Where(s => !s.Deleted);

                if (draftsOnly)
                {
                    albumQ = albumQ.Where(a => a.Status == EntryStatus.Draft);
                }

                if (sortRule == AlbumSortRule.ReleaseDate)
                {
                    albumQ = AddReleaseRestriction(albumQ);
                }

                albumQ = AddDiscTypeRestriction(albumQ, discType);

                return(albumQ.Count());
            }

            if (query.StartsWith("tag:"))
            {
                var tagName = query.Substring(4);

                var tagQ = Query <AlbumTagUsage>()
                           .Where(m => !m.Album.Deleted && m.Tag.Name == tagName);

                if (draftsOnly)
                {
                    tagQ = tagQ.Where(a => a.Album.Status == EntryStatus.Draft);
                }

                tagQ = AddDiscTypeRestriction(tagQ, discType);

                return(tagQ.Count());
            }

            if (query.StartsWith("artist:") || queryParams.ArtistId != 0)
            {
                int artistId;
                if (queryParams.ArtistId != 0)
                {
                    artistId = queryParams.ArtistId;
                }
                else
                {
                    int.TryParse(query.Substring(7), out artistId);
                }

                var albumQ = Query <ArtistForAlbum>()
                             .Where(m => !m.Album.Deleted && m.Artist.Id == artistId);

                if (draftsOnly)
                {
                    albumQ = albumQ.Where(a => a.Album.Status == EntryStatus.Draft);
                }

                albumQ = AddDiscTypeRestriction(albumQ, discType);
                return(albumQ.Count());
            }

            var directQ = Query <Album>()
                          .Where(s => !s.Deleted);

            if (draftsOnly)
            {
                directQ = directQ.Where(a => a.Status == EntryStatus.Draft);
            }

            if (sortRule == AlbumSortRule.ReleaseDate)
            {
                directQ = AddReleaseRestriction(directQ);
            }

            directQ = AddDiscTypeRestriction(directQ, discType);

            directQ = AddNameMatchFilter(directQ, query, nameMatchMode);

            var direct = directQ.ToArray();

            var additionalNamesQ = Query <AlbumName>()
                                   .Where(m => !m.Album.Deleted);

            if (draftsOnly)
            {
                additionalNamesQ = additionalNamesQ.Where(a => a.Album.Status == EntryStatus.Draft);
            }

            additionalNamesQ = AddDiscTypeRestriction(additionalNamesQ, discType);

            additionalNamesQ = additionalNamesQ.AddEntryNameFilter(query, nameMatchMode);

            var additionalNamesAlbumQ = additionalNamesQ.Select(a => a.Album);

            if (sortRule == AlbumSortRule.ReleaseDate)
            {
                additionalNamesAlbumQ = AddReleaseRestriction(additionalNamesAlbumQ);
            }

            var additionalNames = additionalNamesAlbumQ
                                  .Distinct()
                                  .ToArray()
                                  .Where(a => !direct.Contains(a))
                                  .ToArray();

            return(direct.Count() + additionalNames.Count());
        }
Beispiel #13
0
        public PartialFindResult <Album> Find(AlbumQueryParams queryParams)
        {
            var query          = queryParams.Common.Query ?? string.Empty;
            var discType       = queryParams.AlbumType;
            var start          = queryParams.Paging.Start;
            var maxResults     = queryParams.Paging.MaxEntries;
            var draftsOnly     = queryParams.Common.DraftOnly;
            var getTotalCount  = queryParams.Paging.GetTotalCount;
            var nameMatchMode  = queryParams.Common.NameMatchMode;
            var sortRule       = queryParams.SortRule;
            var moveExactToTop = queryParams.Common.MoveExactToTop;

            Album[] entries;
            string  originalQuery   = query;
            bool    foundExactMatch = false;

            if (queryParams.ArtistId == 0 && string.IsNullOrWhiteSpace(query))
            {
                var albumsQ = Query <Album>()
                              .Where(s => !s.Deleted);

                if (draftsOnly)
                {
                    albumsQ = albumsQ.Where(a => a.Status == EntryStatus.Draft);
                }

                albumsQ = AddDiscTypeRestriction(albumsQ, discType);

                albumsQ = AddOrder(albumsQ, sortRule, LanguagePreference);

                entries = albumsQ
                          .Skip(start)
                          .Take(maxResults)
                          .ToArray();

                // TODO: refactor using advanced search parser
            }
            else if (query.StartsWith("tag:"))
            {
                var tagName = query.Substring(4);

                var tagQ = Query <AlbumTagUsage>()
                           .Where(m => !m.Album.Deleted && m.Tag.Name == tagName);

                if (draftsOnly)
                {
                    tagQ = tagQ.Where(a => a.Album.Status == EntryStatus.Draft);
                }

                tagQ    = AddDiscTypeRestriction(tagQ, discType);
                entries = AddOrder(tagQ.Select(m => m.Album), sortRule, LanguagePreference)
                          .Skip(start)
                          .Take(maxResults)
                          .ToArray();

                // TODO: refactor using advanced search parser
            }
            else if (query.StartsWith("artist:") || queryParams.ArtistId != 0)
            {
                int artistId;
                if (queryParams.ArtistId != 0)
                {
                    artistId = queryParams.ArtistId;
                }
                else
                {
                    int.TryParse(query.Substring(7), out artistId);
                }

                var albumQ = Query <ArtistForAlbum>()
                             .Where(m => !m.Album.Deleted && m.Artist.Id == artistId);

                if (draftsOnly)
                {
                    albumQ = albumQ.Where(a => a.Album.Status == EntryStatus.Draft);
                }

                albumQ  = AddDiscTypeRestriction(albumQ, discType);
                entries = AddOrder(albumQ.Select(m => m.Album), sortRule, LanguagePreference)
                          .Skip(start)
                          .Take(maxResults)
                          .ToArray();
            }
            else
            {
                query = query.Trim();

                // Searching by SortNames can be disabled in the future because all names should be included in the Names list anyway.
                var directQ = Query <Album>()
                              .Where(s => !s.Deleted);

                if (draftsOnly)
                {
                    directQ = directQ.Where(a => a.Status == EntryStatus.Draft);
                }

                directQ = AddDiscTypeRestriction(directQ, discType);
                directQ = AddNameMatchFilter(directQ, query, nameMatchMode);

                var direct = AddOrder(directQ, sortRule, LanguagePreference)
                             .ToArray();

                var additionalNamesQ = Query <AlbumName>()
                                       .Where(m => !m.Album.Deleted);

                if (draftsOnly)
                {
                    additionalNamesQ = additionalNamesQ.Where(a => a.Album.Status == EntryStatus.Draft);
                }

                additionalNamesQ = AddDiscTypeRestriction(additionalNamesQ, discType);

                additionalNamesQ = additionalNamesQ.AddEntryNameFilter(query, nameMatchMode);

                var additionalNames =
                    AddOrder(additionalNamesQ.Select(m => m.Album), sortRule, LanguagePreference)
                    .Distinct()
                    .ToArray()
                    .Where(a => !direct.Contains(a));

                entries = direct.Concat(additionalNames)
                          .Skip(start)
                          .Take(maxResults)
                          .ToArray();

                if (moveExactToTop)
                {
                    var exactMatch = entries
                                     .Where(e => e.Names.Any(n => n.Value.StartsWith(query, StringComparison.InvariantCultureIgnoreCase)))
                                     .ToArray();

                    if (exactMatch.Any())
                    {
                        entries         = CollectionHelper.MoveToTop(entries, exactMatch).ToArray();
                        foundExactMatch = true;
                    }
                }
            }

            var count = (getTotalCount ? GetAlbumCount(queryParams, query, discType, draftsOnly, nameMatchMode, sortRule) : 0);

            return(new PartialFindResult <Album>(entries, count, originalQuery, foundExactMatch));
        }
Beispiel #14
0
        //
        // GET: /Album/
        public ActionResult Index(IndexRouteParams routeParams)
        {
            WebHelper.VerifyUserAgent(Request);

            var filter = routeParams.filter;
            var page = routeParams.page;
            var draftsOnly = routeParams.draftsOnly;
            var dType = routeParams.discType ?? DiscType.Unknown;
            var matchMode = routeParams.matchMode ?? NameMatchMode.Auto;
            var sortRule = routeParams.sort ?? AlbumSortRule.Name;
            var viewMode = routeParams.view ?? EntryViewMode.Details;

            if (matchMode == NameMatchMode.Auto && filter != null && filter.Length <= 2)
                matchMode = NameMatchMode.StartsWith;

            var queryParams = new AlbumQueryParams(filter, dType, ((page ?? 1) - 1) * 30, 30, draftsOnly ?? false,
                true, moveExactToTop: false, sortRule: sortRule, nameMatchMode: matchMode);

            var result = Service.Find(queryParams);

            if (page == null && result.TotalCount == 1 && result.Items.Length == 1) {
                return RedirectToAction("Details", new { id = result.Items[0].Id });
            }

            var model = new Index(result, filter, dType, sortRule, viewMode, page, draftsOnly, routeParams);
            SetSearchEntryType(EntryType.Album);

            return View(model);
        }