private IQueryable <Song> CreateQuery( SongQueryParams queryParams, ParsedSongQuery parsedQuery, NameMatchMode?nameMatchMode = null) { var query = Query <Song>() .Where(s => !s.Deleted) .WhereHasName(parsedQuery.Name, nameMatchMode ?? queryParams.Common.NameMatchMode) .WhereHasArtistParticipationStatus(queryParams.ArtistId, queryParams.ArtistParticipationStatus, queryParams.ChildVoicebanks, id => querySource.Load <Artist>(id)) .WhereDraftsOnly(queryParams.Common.DraftOnly) .WhereStatusIs(queryParams.Common.EntryStatus) .WhereHasType(queryParams.SongTypes) .WhereHasTag(!string.IsNullOrEmpty(queryParams.Tag) ? queryParams.Tag : parsedQuery.TagName) .WhereArtistHasTag(parsedQuery.ArtistTag) .WhereArtistHasType(parsedQuery.ArtistType) .WhereHasNicoId(parsedQuery.NicoId) .WhereIdNotIn(queryParams.IgnoredIds) .WhereInUserCollection(queryParams.UserCollectionId) .WhereHasLyrics(queryParams.LyricsLanguages); query = AddScoreFilter(query, queryParams.MinScore); query = AddTimeFilter(query, queryParams.TimeFilter); query = AddPVFilter(query, queryParams.OnlyWithPVs); return(query); }
private IQueryable <Song> CreateQuery( SongQueryParams queryParams, ParsedSongQuery parsedQuery, NameMatchMode?nameMatchMode = null) { var textQuery = !SearchTextQuery.IsNullOrEmpty(parsedQuery.Name) ? new SearchTextQuery(parsedQuery.Name.Query, nameMatchMode ?? parsedQuery.Name.MatchMode, parsedQuery.Name.OriginalQuery) : SearchTextQuery.Empty; textQuery = ProcessAdvancedSearch(textQuery, queryParams); var typesAndTags = ProcessUnifiedTypesAndTags(queryParams); var query = Query <Song>() .WhereNotDeleted() .WhereHasName(textQuery) .WhereHasArtistParticipationStatus(queryParams.ArtistParticipation, _querySource.OfType <Artist>()) .WhereHasArtists <Song, ArtistForSong>(queryParams.ArtistNames) .WhereStatusIs(queryParams.Common.EntryStatus) .WhereHasType(queryParams.SongTypes) .WhereHasTags(queryParams.TagIds, queryParams.ChildTags) .WhereHasTags(queryParams.Tags) .WhereHasTag(parsedQuery.TagName) .WhereHasTypeOrTag(typesAndTags) .WhereArtistHasTag(parsedQuery.ArtistTag) .WhereArtistHasType(parsedQuery.ArtistType) .WhereHasNicoId(parsedQuery.NicoId) .WhereHasPV(parsedQuery.PV) .WhereHasPVService(queryParams.PVServices) .WhereIdIs(parsedQuery.Id) .WhereIdNotIn(queryParams.IgnoredIds) .WhereInUserCollection(queryParams.UserCollectionId) .WhereHasParentSong(queryParams.ParentSongId) .WhereArtistIsFollowedByUser(queryParams.FollowedByUserId) .WhereReleaseEventIs(queryParams.ReleaseEventId) .WherePublishDateIsBetween(parsedQuery.PublishedAfter, parsedQuery.PublishedBefore) .WherePublishDateIsBetween(queryParams.AfterDate, queryParams.BeforeDate) .WhereHasScore(queryParams.MinScore) .WhereCreateDateIsWithin(queryParams.TimeFilter) .WhereHasPV(queryParams.OnlyWithPVs) .WhereMatchFilters(queryParams.AdvancedFilters) .WhereMilliBpmIsBetween(queryParams.MinMilliBpm, queryParams.MaxMilliBpm) .WhereLengthIsBetween(queryParams.MinLength, queryParams.MaxLength); return(query); }
private PartialFindResult <Song> GetSongs(SongQueryParams queryParams, ParsedSongQuery parsedQuery) { var query = CreateQuery(queryParams, parsedQuery); var ids = query .AddOrder(queryParams.SortRule, LanguagePreference) .Select(s => s.Id) .Paged(queryParams.Paging) .ToArray(); var songs = SortByIds(querySource .Query <Song>() .Where(s => ids.Contains(s.Id)) .ToArray(), ids); var count = (queryParams.Paging.GetTotalCount ? query.Count() : 0); return(new PartialFindResult <Song>(songs, count, queryParams.Common.Query, false)); }
private IQueryable <Song> CreateQuery( SongQueryParams queryParams, ParsedSongQuery parsedQuery, NameMatchMode?nameMatchMode = null) { var textQuery = !SearchTextQuery.IsNullOrEmpty(parsedQuery.Name) ? new SearchTextQuery(parsedQuery.Name.Query, nameMatchMode ?? parsedQuery.Name.MatchMode, parsedQuery.Name.OriginalQuery) : SearchTextQuery.Empty; textQuery = ProcessAdvancedSearch(textQuery, queryParams); var query = Query <Song>() .Where(s => !s.Deleted) .WhereHasName(textQuery) .WhereHasArtistParticipationStatus(queryParams.ArtistParticipation, id => querySource.Load <Artist>(id)) .WhereHasArtists <Song, ArtistForSong>(queryParams.ArtistNames) .WhereStatusIs(queryParams.Common.EntryStatus) .WhereHasType(queryParams.SongTypes) .WhereHasTags(queryParams.TagIds, queryParams.ChildTags) .WhereHasTags(queryParams.Tags) .WhereHasTag(parsedQuery.TagName) .WhereArtistHasTag(parsedQuery.ArtistTag) .WhereArtistHasType(parsedQuery.ArtistType) .WhereHasNicoId(parsedQuery.NicoId) .WhereHasPV(parsedQuery.PV) .WhereHasPVService(queryParams.PVServices) .WhereIdIs(parsedQuery.Id) .WhereIdNotIn(queryParams.IgnoredIds) .WhereInUserCollection(queryParams.UserCollectionId) .WherePublishDateIsBetween(parsedQuery.PublishedAfter, parsedQuery.PublishedBefore) .WhereHasScore(queryParams.MinScore) .WhereCreateDateIsWithin(queryParams.TimeFilter) .WhereHasPV(queryParams.OnlyWithPVs) .WhereMatchFilters(queryParams.AdvancedFilters); return(query); }
/// <summary> /// Get songs, searching by exact matches FIRST. /// This mode does not support paging. /// </summary> private PartialFindResult <Song> GetSongsMoveExactToTop(SongQueryParams queryParams, ParsedSongQuery 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 songs = SortByIds( querySource .Query <Song>() .Where(s => ids.Contains(s.Id)) .ToArray(), ids); return(new PartialFindResult <Song>(songs, count, queryParams.Common.Query, true)); }