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); }
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)); }
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); }
/// <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)); }