Exemplo n.º 1
0
        private IQueryable <Artist> CreateQuery(
            ArtistQueryParams queryParams,
            ParsedArtistQuery parsedQuery,
            NameMatchMode?nameMatchMode = null)
        {
            var textQuery = (parsedQuery.HasNameQuery ? queryParams.Common.TextQuery.OverrideMatchMode(nameMatchMode) : ArtistSearchTextQuery.Empty);

            var query = context.Query()
                        .Where(s => !s.Deleted)
                        .WhereHasName_Canonized(textQuery)
                        .WhereDraftsOnly(queryParams.Common.DraftOnly)
                        .WhereStatusIs(queryParams.Common.EntryStatus)
                        .WhereHasExternalLinkUrl(parsedQuery.ExternalLinkUrl)
                        .WhereHasType(queryParams.ArtistTypes)
                        .WhereHasTag(queryParams.Tag)
                        .WhereIdIs(parsedQuery.Id)
                        .WhereIsFollowedByUser(queryParams.UserFollowerId);

            return(query);
        }
Exemplo n.º 2
0
        private IQueryable <Artist> CreateQuery(
            ArtistQueryParams queryParams,
            ParsedArtistQuery parsedQuery,
            NameMatchMode?nameMatchMode = null)
        {
            var textQuery = (parsedQuery.HasNameQuery ? queryParams.Common.TextQuery.OverrideMatchMode(nameMatchMode) : ArtistSearchTextQuery.Empty);

            var query = _context.Query()
                        .Where(s => !s.Deleted)
                        .WhereHasName_Canonized(textQuery)
                        .WhereStatusIs(queryParams.Common.EntryStatus)
                        .WhereHasExternalLinkUrl(parsedQuery.ExternalLinkUrl)
                        .WhereHasType(queryParams.ArtistTypes)
                        .WhereHasTags(queryParams.TagIds, queryParams.ChildTags)
                        .WhereHasTags(queryParams.Tags)
                        .WhereIdIs(parsedQuery.Id)
                        .WhereIsFollowedByUser(queryParams.UserFollowerId)
                        .WhereAllowBaseVoicebanks(queryParams.AllowBaseVoicebanks)
                        .WhereMatchFilters(queryParams.AdvancedFilters);

            return(query);
        }
Exemplo n.º 3
0
        private PartialFindResult <Artist> GetArtistsMoveExactToTop(ArtistQueryParams queryParams, ParsedArtistQuery 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 artist = SortByIds(_context
                                   .Query()
                                   .Where(s => ids.Contains(s.Id))
                                   .ToArray(), ids);

            return(new PartialFindResult <Artist>(artist, count, queryParams.Common.Query));
        }