Ejemplo n.º 1
0
        public AlbumQueryParams(string query, DiscType discType, int start, int maxResults, bool draftsOnly, bool getTotalCount,
            NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sortRule = AlbumSortRule.Name, bool moveExactToTop = false)
        {
            Common = new CommonSearchParams(query, draftsOnly, nameMatchMode, false, moveExactToTop);
            Paging = new PagingProperties(start, maxResults, getTotalCount);

            AlbumType = discType;
            SortRule = sortRule;
        }
Ejemplo n.º 2
0
		private void TestGetMatchModeAndQueryForSearch(string query, string expectedQuery, NameMatchMode? expectedMode = null, NameMatchMode originalMode = NameMatchMode.Auto) {

			var result = FindHelpers.GetMatchModeAndQueryForSearch(query, ref originalMode);

			Assert.AreEqual(expectedQuery, result, "query");
			if (expectedMode != null)
				Assert.AreEqual(expectedMode, originalMode, "matchMode");
	
		}
Ejemplo n.º 3
0
 public CommonSearchParams(string query, bool draftOnly, NameMatchMode nameMatchMode, bool onlyByName, bool moveExactToTop)
     : this()
 {
     DraftOnly = draftOnly;
     NameMatchMode = nameMatchMode;
     Query = query;
     OnlyByName = onlyByName;
     MoveExactToTop = moveExactToTop;
 }
Ejemplo n.º 4
0
        /// <param name="query">Query search string. Can be null or empty, in which case no filtering by name is done.</param>
        /// <param name="songTypes">Allowed song types. Can be null or empy, in which case no filtering by song type is done.</param>
        /// <param name="start">0-based order number of the first item to be returned.</param>
        /// <param name="maxResults">Maximum number of results to be returned.</param>
        /// <param name="draftsOnly">Whether to return only entries with a draft status.</param>
        /// <param name="getTotalCount">Whether to return the total number of entries matching the criteria.</param>
        /// <param name="nameMatchMode">Mode for name maching. Ignored when query string is null or empty.</param>
        /// <param name="sortRule">Sort rule for results.</param>
        /// <param name="moveExactToTop">Whether to move exact match to the top of search results.</param>
        public ArtistQueryParams(string query, ArtistType[] songTypes, int start, int maxResults,
            bool draftsOnly, bool getTotalCount, NameMatchMode nameMatchMode, ArtistSortRule sortRule, bool moveExactToTop)
        {
            Common = new CommonSearchParams(query, draftsOnly, nameMatchMode, true, moveExactToTop);
            Paging = new PagingProperties(start, maxResults, getTotalCount);

            ArtistTypes = songTypes ?? new ArtistType[] { };
            SortRule = sortRule;
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <param name="query">Query search string. Can be null or empty, in which case no filtering by name is done.</param>
        /// <param name="songTypes">Allowed song types. Can be null or empy, in which case no filtering by song type is done.</param>
        /// <param name="start">0-based order number of the first item to be returned.</param>
        /// <param name="maxResults">Maximum number of results to be returned.</param>
        /// <param name="draftsOnly">Whether to return only entries with a draft status.</param>
        /// <param name="getTotalCount">Whether to return the total number of entries matching the criteria.</param>
        /// <param name="nameMatchMode">Mode for name maching. Ignored when query string is null or empty.</param>
        /// <param name="sortRule">Sort rule for results.</param>
        /// <param name="onlyByName">Whether to search items only by name, and not for example NicoId. Ignored when query string is null or empty.</param>
        /// <param name="moveExactToTop">Whether to move exact match to the top of search results.</param>
        /// <param name="ignoredIds">List of entries to be ignored. Can be null in which case no filtering is done.</param>
        public SongQueryParams(string query, SongType[] songTypes, int start, int maxResults,
            bool draftsOnly, bool getTotalCount, NameMatchMode nameMatchMode, SongSortRule sortRule,
            bool onlyByName, bool moveExactToTop, int[] ignoredIds)
        {
            Common = new CommonSearchParams(query, draftsOnly, nameMatchMode, onlyByName, moveExactToTop);
            Paging = new PagingProperties(start, maxResults, getTotalCount);

            SongTypes = songTypes;
            SortRule = sortRule;
            IgnoredIds = ignoredIds;
            TimeFilter = TimeSpan.Zero;
            OnlyWithPVs = false;
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
		private PartialFindResult<EntryForApiContract> CallGetList(
			string query = null, 
			string tag = null,
			EntryStatus? status = null,
			int start = 0, int maxResults = 10, bool getTotalCount = true,
			NameMatchMode nameMatchMode = NameMatchMode.Words,
			EntryOptionalFields fields = EntryOptionalFields.None,
			ContentLanguagePreference lang = ContentLanguagePreference.Default,
			bool ssl = false) {
			
			return queries.GetList(query, tag, status, start, maxResults, getTotalCount, nameMatchMode, fields, lang, ssl);

		}
Ejemplo n.º 9
0
        public PartialFindResult<EntryForApiContract> GetList(
            string query,
            string tag = null,
            EntryStatus? status = null,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            EntryOptionalFields fields = EntryOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default
            )
        {
            var ssl = WebHelper.IsSSL(Request);
            maxResults = GetMaxResults(maxResults);

            return queries.GetList(query, tag, status, start, maxResults, getTotalCount, nameMatchMode, fields, lang, ssl);
        }
Ejemplo n.º 10
0
		private IQueryable<Artist> CreateQuery(
			ArtistQueryParams queryParams, 
			NameMatchMode? nameMatchMode = null) {
			
			var query = context.Query()
				.Where(s => !s.Deleted)
				.WhereHasName_Canonized(queryParams.Common.Query, matchMode: nameMatchMode ?? queryParams.Common.NameMatchMode)
				.WhereDraftsOnly(queryParams.Common.DraftOnly)
				.WhereStatusIs(queryParams.Common.EntryStatus)
				.WhereHasType(queryParams.ArtistTypes)
				.WhereHasTag(queryParams.Tag)
				.WhereIsFollowedByUser(queryParams.UserFollowerId);

			return query;

		}
Ejemplo n.º 11
0
        public static IQueryable<ArtistName> FilterByArtistName(this IQueryable<ArtistName> query, string originalQuery,
            string canonizedName = null, NameMatchMode matchMode = NameMatchMode.Auto, string[] words = null)
        {
            canonizedName = canonizedName ?? ArtistHelper.GetCanonizedName(originalQuery);

            if (FindHelpers.ExactMatch(canonizedName, matchMode)) {

                return query.Where(m => m.Value == canonizedName
                    || m.Value == string.Format("{0}P", canonizedName)
                    || m.Value == string.Format("{0}-P", canonizedName));

            } else {

                return FindHelpers.AddEntryNameFilter(query, canonizedName, matchMode, words);

            }
        }
Ejemplo n.º 12
0
 public Index(PartialFindResult<SongWithAlbumAndPVsContract> result, string filter, NameMatchMode nameMatchMode, SongType songType, string timeFilter, bool onlyWithPVs, 
     SongSortRule sortRule, SongViewMode viewMode,
     bool draftsOnly, int page, int pageSize, IndexRouteParams routeParams)
 {
     ArtistId = routeParams.artistId ?? 0;
     DraftsOnly = draftsOnly;
     Songs = new StaticPagedList<SongWithAlbumAndPVsContract>(result.Items,
         page, pageSize, result.TotalCount);
     Filter = filter;
     NameMatchMode = nameMatchMode;
     SongType = songType;
     Since = timeFilter;
     OnlyWithPVs = onlyWithPVs;
     Sort = sortRule;
     ViewMode = viewMode;
     RouteParams = routeParams;
 }
Ejemplo n.º 13
0
        public ActionResult ByName(string query, ContentLanguagePreference? lang, int? start, int? maxResults, NameMatchMode? nameMatchMode,
            string callback, DataFormat format = DataFormat.Auto)
        {
            var param = new SongQueryParams(query, new SongType[] {}, 0, defaultMax, false, true, NameMatchMode.Exact, SongSortRule.Name, true, false, new int[] {});

            if (start.HasValue)
                param.Paging.Start = start.Value;

            if (maxResults.HasValue)
                param.Paging.MaxEntries = Math.Min(maxResults.Value, defaultMax);

            if (nameMatchMode.HasValue)
                param.Common.NameMatchMode = nameMatchMode.Value;

            var songs = Service.Find(s => new SongForApiContract(s, lang ?? ContentLanguagePreference.Default), param);

            return Object(songs, format, callback);
        }
Ejemplo n.º 14
0
        public PartialFindResult<TagForApiContract> GetList(
            string query = "",
            bool allowAliases = false,
            string categoryName = "",
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            TagOptionalFields fields = TagOptionalFields.None)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            var ssl = WebHelper.IsSSL(Request);
            var queryParams = new CommonSearchParams(query, false, nameMatchMode, false, false);
            var paging = new PagingProperties(start, maxResults, getTotalCount);

            var tags = queries.Find(t => new TagForApiContract(t, thumbPersister, ssl, fields),
                queryParams, paging,
                allowAliases, categoryName);

            return tags;
        }
Ejemplo n.º 15
0
        public PartialFindResult <ReleaseEventForApiContract> GetList(
            string query = "",
            NameMatchMode nameMatchMode = NameMatchMode.Auto,
            int seriesId             = 0,
            DateTime?afterDate       = null,
            DateTime?beforeDate      = null,
            EventCategory category   = EventCategory.Unspecified,
            int?userCollectionId     = null,
            [FromUri] int[] tagId    = null,
            bool childTags           = false,
            [FromUri] int[] artistId = null,
            bool childVoicebanks     = false,
            bool includeMembers      = false,
            EntryStatus?status       = null,
            int start          = 0,
            int maxResults     = defaultMax,
            bool getTotalCount = false,
            EventSortRule sort = EventSortRule.Name,
            ReleaseEventOptionalFields fields = ReleaseEventOptionalFields.None,
            ContentLanguagePreference lang    = ContentLanguagePreference.Default
            )
        {
            var textQuery   = SearchTextQuery.Create(query, nameMatchMode);
            var queryParams = new EventQueryParams {
                TextQuery       = textQuery,
                SeriesId        = seriesId,
                AfterDate       = afterDate,
                BeforeDate      = beforeDate,
                Category        = category,
                UserId          = userCollectionId ?? 0,
                ArtistIds       = new EntryIdsCollection(artistId),
                ChildVoicebanks = childVoicebanks,
                IncludeMembers  = includeMembers,
                ChildTags       = childTags,
                TagIds          = tagId,
                EntryStatus     = status,
                Paging          = new PagingProperties(start, maxResults, getTotalCount),
                SortRule        = sort
            };

            return(queries.Find(e => new ReleaseEventForApiContract(e, lang, fields, thumbPersister, WebHelper.IsSSL(Request)), queryParams));
        }
Ejemplo n.º 16
0
        public PartialFindResult <VenueForApiContract> GetList(
            string query = "",
            VenueOptionalFields fields = VenueOptionalFields.None,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            NameMatchMode nameMatchMode    = NameMatchMode.Auto,
            ContentLanguagePreference lang = ContentLanguagePreference.Default,
            VenueSortRule sortRule         = VenueSortRule.Name,
            double?latitude = null, double?longitude = null, double?radius = null, DistanceUnit distanceUnit = DistanceUnit.Kilometers)
        {
            var textQuery   = SearchTextQuery.Create(query, nameMatchMode);
            var queryParams = new VenueQueryParams {
                Coordinates  = new GeoPointQueryParams(latitude, longitude),
                DistanceUnit = distanceUnit,
                Paging       = new PagingProperties(start, maxResults, getTotalCount),
                Radius       = radius,
                SortRule     = sortRule,
                TextQuery    = textQuery
            };

            return(queries.Find(v => new VenueForApiContract(v, lang, fields), queryParams));
        }
Ejemplo n.º 17
0
        public PartialFindResult <SongListForApiContract> GetSongLists(
            int id,
            string query                = "",
            [FromUri] int[] tagId       = null,
            bool childTags              = false,
            NameMatchMode nameMatchMode = NameMatchMode.Auto,
            int start                     = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongListSortRule sort         = SongListSortRule.Name,
            SongListOptionalFields?fields = null)
        {
            var textQuery   = SearchTextQuery.Create(query, nameMatchMode);
            var queryParams = new SongListQueryParams {
                TextQuery = textQuery,
                SortRule  = sort,
                Paging    = new PagingProperties(start, maxResults, getTotalCount),
                TagIds    = tagId,
                ChildTags = childTags
            };

            return(queries.GetCustomSongLists(id, queryParams, fields ?? SongListOptionalFields.None));
        }
Ejemplo n.º 18
0
        public ActionResult ByName(string query, ContentLanguagePreference? lang, int? start, int? maxResults, NameMatchMode? nameMatchMode,
            string callback, DataFormat format = DataFormat.Auto)
        {
            if (string.IsNullOrEmpty(query))
                return Object(new PartialFindResult<SongForApiContract>(), format, callback);

            var param = new ArtistQueryParams(query, new ArtistType[] { }, 0, defaultMax, false, true, NameMatchMode.Exact, ArtistSortRule.Name, false);

            if (start.HasValue)
                param.Paging.Start = start.Value;

            if (maxResults.HasValue)
                param.Paging.MaxEntries = Math.Min(maxResults.Value, defaultMax);

            if (nameMatchMode.HasValue)
                param.Common.NameMatchMode = nameMatchMode.Value;

            var songs = Service.FindArtists(s => new ArtistForApiContractOld(s, null, lang ?? ContentLanguagePreference.Default), param);

            return Object(songs, format, callback);
        }
Ejemplo n.º 19
0
        public PartialFindResult <RatedSongForUserForApiContract> GetRatedSongs(
            int id,
            string query                    = "",
            string tagName                  = null,
            [FromUri] int[] tagId           = null,
            [FromUri] int[] artistId        = null,
            bool childVoicebanks            = false,
            SongVoteRating?rating           = null,
            int?songListId                  = null,
            bool groupByRating              = true,
            [FromUri] PVServices?pvServices = null,
            [FromUri] AdvancedSearchFilter[] advancedFilters = null,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            RatedSongForUserSortRule?sort  = null,
            NameMatchMode nameMatchMode    = NameMatchMode.Auto,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);

            var queryParams = new RatedSongQueryParams(id, new PagingProperties(start, maxResults, getTotalCount))
            {
                TextQuery       = textQuery,
                SortRule        = sort ?? RatedSongForUserSortRule.Name,
                ArtistIds       = artistId,
                ChildVoicebanks = childVoicebanks,
                FilterByRating  = rating ?? SongVoteRating.Nothing,
                GroupByRating   = groupByRating,
                PVServices      = pvServices,
                SonglistId      = songListId ?? 0,
                TagIds          = tagId,
                TagName         = tagName,
                AdvancedFilters = advancedFilters
            };

            var songs = queries.GetRatedSongs(queryParams, ratedSong => new RatedSongForUserForApiContract(ratedSong, lang, fields));

            return(songs);
        }
Ejemplo n.º 20
0
        public PartialFindResult <AlbumForUserForApiContract> GetAlbumCollection(
            int id,
            string query = "",
            int?tagId    = null,
            string tag   = null,
            int?artistId = null,
            [FromUri] PurchaseStatuses?purchaseStatuses = null,
            int releaseEventId  = 0,
            DiscType albumTypes = DiscType.Unknown,
            [FromUri] AdvancedSearchFilter[] advancedFilters = 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)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);
            var ssl       = WebHelper.IsSSL(Request);

            var queryParams = new AlbumCollectionQueryParams(id, new PagingProperties(start, maxResults, getTotalCount))
            {
                AlbumType      = albumTypes,
                ArtistId       = artistId ?? 0,
                FilterByStatus = purchaseStatuses != null?purchaseStatuses.Value.ToIndividualSelections().ToArray() : null,
                                     TextQuery       = textQuery,
                                     ReleaseEventId  = releaseEventId,
                                     Sort            = sort ?? AlbumSortRule.Name,
                                     TagId           = tagId ?? 0,
                                     Tag             = tag,
                                     AdvancedFilters = advancedFilters
            };

            var albums = queries.GetAlbumCollection(queryParams, (afu, shouldShowCollectionStatus) =>
                                                    new AlbumForUserForApiContract(afu, lang, thumbPersister, ssl, fields, shouldShowCollectionStatus));

            return(albums);
        }
Ejemplo n.º 21
0
        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,
            bool preferAccurateMatches     = false,
            bool deleted                   = false,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            AlbumOptionalFields fields     = AlbumOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);

            var queryParams = new AlbumQueryParams(textQuery, discTypes, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, sort ?? AlbumSortRule.Name, preferAccurateMatches)
            {
                Tag      = tag,
                ArtistId = artistId ?? 0,
                ArtistParticipationStatus = artistParticipationStatus,
                ChildVoicebanks           = childVoicebanks,
                Barcode = barcode,
                Deleted = deleted
            };

            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);
        }
Ejemplo n.º 22
0
        public PartialFindResult <SongForApiContract> GetList(
            string query       = "",
            SongType songTypes = SongType.Unspecified,
            string tag         = null,
            int?artistId       = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks = false,
            bool onlyWithPvs     = false,
            int?since            = null,
            [FromUri] ContentLanguageSelections?lyrics = null,
            int?userCollectionId           = null,
            EntryStatus?status             = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule sort              = SongSortRule.Name,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);
            var types = songTypes != SongType.Unspecified ? new[] { songTypes } : new SongType[0];

            var param = new SongQueryParams(query, types, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, nameMatchMode, sort, false, false, null)
            {
                Tag         = tag,
                OnlyWithPVs = onlyWithPvs,
                ArtistId    = artistId ?? 0,
                ArtistParticipationStatus = artistParticipationStatus,
                ChildVoicebanks           = childVoicebanks,
                TimeFilter      = since.HasValue ? TimeSpan.FromHours(since.Value) : TimeSpan.Zero,
                LyricsLanguages = lyrics != null?lyrics.Value.ToIndividualSelections().ToArray() : null,
                                      UserCollectionId = userCollectionId ?? 0
            };

            param.Common.EntryStatus = status;

            var artists = service.Find(s => new SongForApiContract(s, null, lang, fields), param);

            return(artists);
        }
Ejemplo n.º 23
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));
        }
Ejemplo n.º 24
0
        public T FindFirst <T>(Func <Song, T> fac, string[] query, NameMatchMode nameMatchMode)
            where T : class
        {
            return(HandleQuery(session => {
                foreach (var q in query.Where(q => !string.IsNullOrWhiteSpace(q)))
                {
                    var result = Find(session,
                                      new SongQueryParams {
                        Common = new CommonSearchParams {
                            Query = q, NameMatchMode = nameMatchMode, OnlyByName = true, MoveExactToTop = true
                        },
                        Paging = new PagingProperties(0, 30, false)
                    });

                    if (result.Items.Any())
                    {
                        return fac(result.Items.First());
                    }
                }

                return null;
            }));
        }
Ejemplo n.º 25
0
        public PartialFindResult <ArtistForApiContract> GetList(
            string query               = "",
            string artistTypes         = null,
            bool allowBaseVoicebanks   = true,
            [FromUri] string[] tagName = null,
            [FromUri] int[] tagId      = null,
            bool childTags             = false,
            int?followedByUserId       = null,
            EntryStatus?status         = null,
            [FromUri] AdvancedSearchFilter[] advancedFilters = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            ArtistSortRule sort            = ArtistSortRule.Name,
            bool preferAccurateMatches     = false,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            ArtistOptionalFields fields    = ArtistOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var textQuery = ArtistSearchTextQuery.Create(query, nameMatchMode);
            var types     = EnumVal <ArtistType> .ParseMultiple(artistTypes);

            var param = new ArtistQueryParams(textQuery, types, start, Math.Min(maxResults, absoluteMax), getTotalCount, sort, preferAccurateMatches)
            {
                Tags                = tagName,
                TagIds              = tagId,
                ChildTags           = childTags,
                UserFollowerId      = followedByUserId ?? 0,
                AllowBaseVoicebanks = allowBaseVoicebanks,
                AdvancedFilters     = advancedFilters
            };

            param.Common.EntryStatus = status;

            var ssl     = WebHelper.IsSSL(Request);
            var artists = service.FindArtists(s => new ArtistForApiContract(s, lang, thumbPersister, ssl, fields), param);

            return(artists);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Gets match mode and query for search.
        ///
        /// Handles short query terms and wildcard searches ("*" in the end).
        /// Will only be applied if the current match mode is Auto.
        /// </summary>
        /// <param name="query">Text query. Can be null or empty.</param>
        /// <param name="matchMode">Current match mode. If Auto, will be set if something else besides Auto.</param>
        /// <param name="defaultMode">Default match mode to be used for normal queries.</param>
        /// <returns>Text query. Wildcard characters are removed. Can be null or empty, if original query is.</returns>
        public static string GetMatchModeAndQueryForSearch(string query, ref NameMatchMode matchMode, NameMatchMode defaultMode = NameMatchMode.Words)
        {
            if (string.IsNullOrEmpty(query))
            {
                return(query);
            }

            // Remove SQL wildcard characters from the query, regardless of name match mode
            query = CleanTerm(query.Trim());

            // If name match mode is already decided, there's nothing more to do
            if (matchMode != NameMatchMode.Auto)
            {
                return(query);
            }

            if (query.Length > 1 && query.EndsWith("*"))
            {
                matchMode = NameMatchMode.StartsWith;
                return(query.Substring(0, query.Length - 1));
            }

            if (query.Length > 2 && query.StartsWith("\"") && query.EndsWith("\""))
            {
                matchMode = NameMatchMode.Exact;
                return(query.Substring(1, query.Length - 2));
            }

            if (query.Length <= 2)
            {
                matchMode = NameMatchMode.StartsWith;
                return(query);
            }

            matchMode = defaultMode;
            return(query);
        }
Ejemplo n.º 27
0
		public static IQueryable<Tag> AddTagNameFilter(this IQueryable<Tag> query, string nameFilter, NameMatchMode matchMode) {

			return WhereHasName(query, nameFilter, matchMode);

		}
Ejemplo n.º 28
0
        public PartialFindResult <SongWithAlbumAndPVsContract> FindSongs(string term, int maxResults, NameMatchMode nameMatchMode = NameMatchMode.Auto)
        {
            var sampleSize = Math.Min(maxResults * 2, 30);

            var results = songService.FindWithAlbum(new SongQueryParams(
                                                        SearchTextQuery.Create(term, nameMatchMode), new SongType[] {}, 0, sampleSize, true, SongSortRule.Name, false, true, null), false);

            return(new PartialFindResult <SongWithAlbumAndPVsContract>(results.Items.Take(maxResults).ToArray(), results.TotalCount, results.Term));
        }
Ejemplo n.º 29
0
 public string[] GetNames(string query = "", NameMatchMode nameMatchMode = NameMatchMode.Auto, int maxResults = 10)
 {
     return(otherService.FindNames(SearchTextQuery.Create(query, nameMatchMode), maxResults));
 }
Ejemplo n.º 30
0
 public string[] GetCategoryNamesList(string query = "", NameMatchMode nameMatchMode = NameMatchMode.Auto)
 {
     return(queries.FindCategories(SearchTextQuery.Create(query, nameMatchMode)));
 }
Ejemplo n.º 31
0
 public PartialFindResult <AlbumContract> FindAlbums(string term, int maxResults,
                                                     NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
 {
     return(albumService.Find(SearchTextQuery.Create(term, nameMatchMode), DiscType.Unknown, 0, maxResults, true, moveExactToTop: true, sortRule: sort));
 }
Ejemplo n.º 32
0
        public PartialFindResult<SongForApiContract> GetList(
            string query = "",
            SongType songTypes = SongType.Unspecified,
            string tag = null,
            int? artistId = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks = false,
            bool onlyWithPvs = false,
            int? since = null,
            [FromUri] ContentLanguageSelections? lyrics = null,
            int? userCollectionId = null,
            EntryStatus? status = null,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule sort = SongSortRule.Name,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            SongOptionalFields fields = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);
            var types = songTypes != SongType.Unspecified ? new[] { songTypes } : new SongType[0];

            var param = new SongQueryParams(query, types, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, nameMatchMode, sort, false, false, null) {
                Tag = tag,
                OnlyWithPVs = onlyWithPvs,
                ArtistId = artistId ?? 0,
                ArtistParticipationStatus = artistParticipationStatus,
                ChildVoicebanks = childVoicebanks,
                TimeFilter = since.HasValue ? TimeSpan.FromHours(since.Value) : TimeSpan.Zero,
                LyricsLanguages = lyrics != null ? lyrics.Value.ToIndividualSelections().ToArray() : null,
                UserCollectionId = userCollectionId ?? 0
            };
            param.Common.EntryStatus = status;

            var artists = service.Find(s => new SongForApiContract(s, null, lang, fields), param);

            return artists;
        }
Ejemplo n.º 33
0
        public PartialFindResult<RatedSongForUserForApiContract> GetRatedSongs(
            int userId,
            string query = "",
            string tag = null,
            int? artistId = null,
            bool childVoicebanks = false,
            SongVoteRating? rating = null,
            int? songListId = null,
            bool groupByRating = true,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule? sort = null,
            NameMatchMode nameMatchMode = NameMatchMode.Auto,
            SongOptionalFields fields = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);

            var queryParams = new RatedSongQueryParams(userId, new PagingProperties(start, maxResults, getTotalCount)) {
                Query = query,
                NameMatchMode = nameMatchMode,
                SortRule = sort ?? SongSortRule.Name,
                ArtistId = artistId ?? 0,
                ChildVoicebanks = childVoicebanks,
                FilterByRating = rating ?? SongVoteRating.Nothing,
                GroupByRating = groupByRating,
                SonglistId = songListId ?? 0,
                Tag = tag
            };

            var songs = queries.GetRatedSongs(queryParams, ratedSong => new RatedSongForUserForApiContract(ratedSong, lang, fields));
            return songs;
        }
Ejemplo n.º 34
0
        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;
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Filters a song query by a name query.
 /// </summary>
 /// <param name="query">Song query. Cannot be null.</param>
 /// <param name="nameFilter">Name filter string. If null or empty, no filtering is done.</param>
 /// <param name="matchMode">Desired mode for matching names.</param>
 /// <param name="words">
 /// List of words for the words search mode.
 /// Can be null, in which case the words list will be parsed from <paramref name="nameFilter"/>.
 /// </param>
 /// <returns>Filtered query. Cannot be null.</returns>
 public static IQueryable <Song> WhereHasName(this IQueryable <Song> query, string nameFilter,
                                              NameMatchMode matchMode, string[] words = null)
 {
     return(query.WhereHasNameGeneric <Song, SongName>(nameFilter, matchMode, words));
 }
Ejemplo n.º 36
0
        public static IQueryable <T> WhereHasLink <T, TLink>(this IQueryable <T> query, string url, NameMatchMode matchMode)
            where T : IEntryWithLinks <TLink> where TLink : WebLink
        {
            switch (matchMode)
            {
            case NameMatchMode.StartsWith:
                return(query.Where(e => e.WebLinks.Any(l => l.Url.StartsWith(url))));

            case NameMatchMode.Partial:
            case NameMatchMode.Words:
                return(query.Where(e => e.WebLinks.Any(l => l.Url.Contains(url))));

            default:
                return(query.Where(e => e.WebLinks.Any(l => l.Url == url)));
            }
        }
Ejemplo n.º 37
0
 public TagSearchTextQuery(string?query, NameMatchMode matchMode, string?originalQuery, string[]?words = null)
     : base(query, matchMode, originalQuery, words)
 {
 }
Ejemplo n.º 38
0
        public PartialFindResult<SongWithAlbumAndPVsContract> FindSongs(string term, int maxResults, NameMatchMode nameMatchMode = NameMatchMode.Auto)
        {
            var sampleSize = Math.Min(maxResults * 2, 30);

            var results = Services.Songs.FindWithAlbum(new SongQueryParams(
                term, new SongType[] {}, 0, sampleSize, false, true, nameMatchMode, SongSortRule.Name, false, true, null), false);

            return new PartialFindResult<SongWithAlbumAndPVsContract>(results.Items.Take(maxResults).ToArray(), results.TotalCount, results.Term, results.FoundExactMatch);
        }
Ejemplo n.º 39
0
 public PartialFindResult<ArtistContract> FindArtists(string term, int maxResults, NameMatchMode nameMatchMode = NameMatchMode.Auto)
 {
     return Services.Artists.FindArtists(new ArtistQueryParams(term, new ArtistType[] {}, 0, maxResults, false, true, nameMatchMode, ArtistSortRule.Name, true));
 }
Ejemplo n.º 40
0
        public PartialFindResult <SongForApiContract> GetList(
            string query               = "",
            string songTypes           = null,
            DateTime?afterDate         = null,
            DateTime?beforeDate        = null,
            [FromUri] string[] tagName = null,
            [FromUri] int[] tagId      = null,
            bool childTags             = false,
            bool unifyTypesAndTags     = false,
            [FromUri] int[] artistId   = null,
            ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything,
            bool childVoicebanks            = false,
            bool includeMembers             = false,
            bool onlyWithPvs                = false,
            [FromUri] PVServices?pvServices = null,
            int?since            = null,
            int?minScore         = null,
            int?userCollectionId = null,
            int?releaseEventId   = null,
            int?parentSongId     = null,
            EntryStatus?status   = null,
            [FromUri] AdvancedSearchFilter[] advancedFilters = null,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule sort              = SongSortRule.Name,
            bool preferAccurateMatches     = false,
            NameMatchMode nameMatchMode    = NameMatchMode.Exact,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);
            var types     = EnumVal <SongType> .ParseMultiple(songTypes);

            var param = new SongQueryParams(textQuery, types, start, Math.Min(maxResults, absoluteMax), getTotalCount, sort, false, preferAccurateMatches, null)
            {
                ArtistParticipation =
                {
                    ArtistIds       = artistId,
                    Participation   = artistParticipationStatus,
                    ChildVoicebanks = childVoicebanks,
                    IncludeMembers  = includeMembers
                },
                AfterDate              = afterDate,
                BeforeDate             = beforeDate,
                TagIds                 = tagId,
                Tags                   = tagName,
                ChildTags              = childTags,
                UnifyEntryTypesAndTags = unifyTypesAndTags,
                OnlyWithPVs            = onlyWithPvs,
                TimeFilter             = since.HasValue ? TimeSpan.FromHours(since.Value) : TimeSpan.Zero,
                MinScore               = minScore ?? 0,
                PVServices             = pvServices,
                UserCollectionId       = userCollectionId ?? 0,
                ReleaseEventId         = releaseEventId ?? 0,
                ParentSongId           = parentSongId ?? 0,
                AdvancedFilters        = advancedFilters,
                LanguagePreference     = lang
            };

            param.Common.EntryStatus = status;

            var artists = service.Find(s => new SongForApiContract(s, null, lang, fields), param);

            return(artists);
        }
Ejemplo n.º 41
0
 protected IQueryable <T> AddNameMatchFilter <T>(IQueryable <T> criteria, string name, NameMatchMode matchMode)
     where T : IEntryWithNames
 {
     return(FindHelpers.AddSortNameFilter(criteria, name, matchMode));
 }
Ejemplo n.º 42
0
        /// <summary>
        /// Filters a song link query by a name query.
        /// </summary>
        /// <param name="query">Song query. Cannot be null.</param>
        /// <param name="nameFilter">Name filter string. If null or empty, no filtering is done.</param>
        /// <param name="matchMode">Desired mode for matching names.</param>
        /// <param name="words">
        /// List of words for the words search mode.
        /// Can be null, in which case the words list will be parsed from <paramref name="nameFilter"/>.
        /// </param>
        /// <returns>Filtered query. Cannot be null.</returns>
        /// <remarks>
        /// Note: this code should be optimized after switching to EF.
        /// Cannot be optimized as is for NH.
        /// </remarks>
        public static IQueryable <T> WhereChildHasName <T>(this IQueryable <T> query, string nameFilter,
                                                           NameMatchMode matchMode, string[] words = null) where T : ISongLink
        {
            if (string.IsNullOrEmpty(nameFilter))
            {
                return(query);
            }

            switch (FindHelpers.GetMatchMode(nameFilter, matchMode))
            {
            case NameMatchMode.Exact:
                return(query.Where(m => m.Song.Names.Names.Any(n => n.Value == nameFilter)));

            case NameMatchMode.Partial:
                return(query.Where(m => m.Song.Names.Names.Any(n => n.Value.Contains(nameFilter))));

            case NameMatchMode.StartsWith:
                return(query.Where(m => m.Song.Names.Names.Any(n => n.Value.StartsWith(nameFilter))));

            case NameMatchMode.Words:
                words = words ?? FindHelpers.GetQueryWords(nameFilter);

                switch (words.Length)
                {
                case 1:
                    query = query.Where(q => q.Song.Names.Names.Any(n => n.Value.Contains(words[0])));
                    break;

                case 2:
                    query = query.Where(q =>
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[1]))
                                        );
                    break;

                case 3:
                    query = query.Where(q =>
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[2]))
                                        );
                    break;

                case 4:
                    query = query.Where(q =>
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[2])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[3]))
                                        );
                    break;

                case 5:
                    query = query.Where(q =>
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[2])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[3])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[4]))
                                        );
                    break;

                case 6:
                    query = query.Where(q =>
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[2])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[3])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[4])) &&
                                        q.Song.Names.Names.Any(n => n.Value.Contains(words[5]))
                                        );
                    break;
                }
                return(query);
            }

            return(query);
        }
Ejemplo n.º 43
0
        public PartialFindResult<ArtistForApiContract> GetList(
            string query = "",
            ArtistTypes artistTypes = ArtistTypes.Nothing,
            string tag = null,
            int? followedByUserId = null,
            EntryStatus? status = null,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            ArtistSortRule sort = ArtistSortRule.Name,
            NameMatchMode nameMatchMode = NameMatchMode.Exact,
            ArtistOptionalFields fields = ArtistOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);
            var types = ArtistHelper.GetArtistTypesFromFlags(artistTypes);

            var param = new ArtistQueryParams(query, types, start, Math.Min(maxResults, absoluteMax), false, getTotalCount, nameMatchMode, sort, false) {
                Tag = tag,
                UserFollowerId = followedByUserId ?? 0
            };
            param.Common.EntryStatus = status;

            var ssl = WebHelper.IsSSL(Request);
            var artists = service.FindArtists(s => new ArtistForApiContract(s, lang, thumbPersister, ssl, fields), param);

            return artists;
        }
Ejemplo n.º 44
0
        public static IQueryable <ArtistName> FilterByArtistName(this IQueryable <ArtistName> query, string originalQuery,
                                                                 string canonizedName = null, NameMatchMode matchMode = NameMatchMode.Auto, string[] words = null)
        {
            canonizedName = canonizedName ?? ArtistHelper.GetCanonizedName(originalQuery);

            if (FindHelpers.ExactMatch(canonizedName, matchMode))
            {
                return(query.Where(m => m.Value == canonizedName ||
                                   m.Value == string.Format("{0}P", canonizedName) ||
                                   m.Value == string.Format("{0}-P", canonizedName)));
            }
            else
            {
                return(FindHelpers.AddEntryNameFilter(query, canonizedName, matchMode, words));
            }
        }
Ejemplo n.º 45
0
 public static IEnumerable <SearchTextQuery> Create(IEnumerable <string> names, NameMatchMode selectedMode = NameMatchMode.Auto, NameMatchMode defaultMode = NameMatchMode.Words)
 {
     return(names.Select(n => Create(n, selectedMode, defaultMode)));
 }
Ejemplo n.º 46
0
 public IEnumerable <string> GetNames(string query = "", NameMatchMode nameMatchMode = NameMatchMode.Auto, int maxResults = 10, bool includeDisabled = false)
 => queries.FindNames(SearchTextQuery.Create(query, nameMatchMode), maxResults, includeDisabled);
Ejemplo n.º 47
0
        public PartialFindResult<AlbumForUserForApiContract> GetAlbumCollection(
            int userId,
            string query = "",
            string tag = null,
            int? artistId = null,
            [FromUri] PurchaseStatuses? purchaseStatuses = null,
            string releaseEventName = 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)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            query = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);
            var ssl = WebHelper.IsSSL(Request);

            var queryParams = new AlbumCollectionQueryParams(userId, new PagingProperties(start, maxResults, getTotalCount)) {
                ArtistId = artistId ?? 0,
                FilterByStatus = purchaseStatuses != null ? purchaseStatuses.Value.ToIndividualSelections().ToArray() : null,
                NameMatchMode = nameMatchMode,
                Query = query,
                ReleaseEventName = releaseEventName,
                Sort = sort ?? AlbumSortRule.Name,
                Tag = tag
            };

            var albums = queries.GetAlbumCollection(queryParams, (afu, shouldShowCollectionStatus) =>
                new AlbumForUserForApiContract(afu, lang, thumbPersister, ssl, fields, shouldShowCollectionStatus));

            return albums;
        }
Ejemplo n.º 48
0
		/// <summary>
		/// Filters query by canonized artist name.
		/// This means that any P suffixes are ignored.
		/// </summary>
		/// <param name="query">Artist query. Cannot be null.</param>
		/// <param name="originalQuery">Original title query. Can be null or empty.</param>
		/// <param name="canonizedName">Canonized artist name if available. Can be null, in which case the canonized name will be parsed from originalQuery.</param>
		/// <param name="matchMode">Name match mode.</param>
		/// <param name="words">Words list if available. Can be null in which case words list is parsed.</param>
		/// <returns>Filtered query. Cannot be null.</returns>
		public static IQueryable<Artist> WhereHasName_Canonized(this IQueryable<Artist> query, string originalQuery,
			string canonizedName = null, NameMatchMode matchMode = NameMatchMode.Auto, string[] words = null) {

			canonizedName = canonizedName ?? ArtistHelper.GetCanonizedName(originalQuery);

			if (string.IsNullOrEmpty(canonizedName))
				return query;

			if (FindHelpers.ExactMatch(canonizedName, matchMode)) {

				return query.Where(m => m.Names.Names.Any(n => 
					n.Value == canonizedName
					|| n.Value == string.Format("{0}P", canonizedName)
					|| n.Value == string.Format("{0}-P", canonizedName)));

			} else {

				return query.WhereHasName(canonizedName, matchMode, words);

			}

		}
Ejemplo n.º 49
0
        public SongDetailsContract GetSongDetails(string term, ContentLanguagePreference?language = null, NameMatchMode matchMode = NameMatchMode.Auto)
        {
            if (language.HasValue)
            {
                userPermissionContext.LanguagePreferenceSetting.OverrideRequestValue(language.Value);
            }

            var song = songService.FindFirstDetails(SearchTextQuery.Create(term, matchMode));

            return(song);
        }
		/// <summary>
		/// Filters a song link query by a name query.
		/// </summary>
		/// <param name="query">Song query. Cannot be null.</param>
		/// <param name="nameFilter">Name filter string. If null or empty, no filtering is done.</param>
		/// <param name="matchMode">Desired mode for matching names.</param>
		/// <param name="words">
		/// List of words for the words search mode. 
		/// Can be null, in which case the words list will be parsed from <paramref name="nameFilter"/>.
		/// </param>
		/// <returns>Filtered query. Cannot be null.</returns>
		/// <remarks>
		/// Note: this code should be optimized after switching to EF.
		/// Cannot be optimized as is for NH.
		/// </remarks>
		public static IQueryable<AlbumForUser> WhereHasName(this IQueryable<AlbumForUser> query, string nameFilter, 
			NameMatchMode matchMode, string[] words = null) {

			if (string.IsNullOrEmpty(nameFilter))
				return query;

			switch (FindHelpers.GetMatchMode(nameFilter, matchMode)) {
				case NameMatchMode.Exact:
					return query.Where(m => m.Album.Names.Names.Any(n => n.Value == nameFilter));

				case NameMatchMode.Partial:
					return query.Where(m => m.Album.Names.Names.Any(n => n.Value.Contains(nameFilter)));

				case NameMatchMode.StartsWith:
					return query.Where(m => m.Album.Names.Names.Any(n => n.Value.StartsWith(nameFilter)));

				case NameMatchMode.Words:
					words = words ?? FindHelpers.GetQueryWords(nameFilter);

					switch (words.Length) {
						case 1:
							query = query.Where(q => q.Album.Names.Names.Any(n => n.Value.Contains(words[0])));
							break;
						case 2:
							query = query.Where(q => 
								q.Album.Names.Names.Any(n => n.Value.Contains(words[0]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[1]))
							);
							break;
						case 3:
							query = query.Where(q => 
								q.Album.Names.Names.Any(n => n.Value.Contains(words[0]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[1]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[2]))
							);
							break;
						case 4:
							query = query.Where(q => 
								q.Album.Names.Names.Any(n => n.Value.Contains(words[0]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[1]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[2]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[3]))
							);
							break;
						case 5:
							query = query.Where(q => 
								q.Album.Names.Names.Any(n => n.Value.Contains(words[0]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[1]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[2]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[3]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[4]))
							);
							break;
						case 6:
							query = query.Where(q => 
								q.Album.Names.Names.Any(n => n.Value.Contains(words[0]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[1]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[2]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[3]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[4]))
								&& q.Album.Names.Names.Any(n => n.Value.Contains(words[5]))
							);
							break;
					}
					return query;

			}

			return query;

		}
Ejemplo n.º 51
0
 public PartialFindResult <ArtistContract> FindArtists(string term, int maxResults, NameMatchMode nameMatchMode = NameMatchMode.Auto)
 {
     return(artistService.FindArtists(new ArtistQueryParams(ArtistSearchTextQuery.Create(term, nameMatchMode), new ArtistType[] {}, 0, maxResults, true, ArtistSortRule.Name, true)));
 }
Ejemplo n.º 52
0
 public IEnumerable <string> GetFeaturedListNames(string query = "",
                                                  NameMatchMode nameMatchMode = NameMatchMode.Auto,
                                                  SongListFeaturedCategory?featuredCategory = null,
                                                  int maxResults = 10) => _queries.GetFeaturedListNames(query, nameMatchMode, featuredCategory, maxResults);
Ejemplo n.º 53
0
        public PartialFindResult <EntryForApiContract> GetList(
            string query,
            int[] tagIds,
            string[] tags,
            bool childTags,
            EntryStatus?status,
            int start, int maxResults, bool getTotalCount,
            EntrySortRule sort,
            NameMatchMode nameMatchMode,
            EntryOptionalFields fields,
            ContentLanguagePreference lang,
            bool ssl,
            bool searchTags = false
            )
        {
            var textQuery       = SearchTextQuery.Create(query, nameMatchMode);
            var artistTextQuery = ArtistSearchTextQuery.Create(query, nameMatchMode);             // Can't use the existing words collection here as they are noncanonized

            return(repository.HandleQuery(ctx => {
                // Get all applicable names per entry type
                var artistQuery = ctx.OfType <Artist>().Query()
                                  .Where(a => !a.Deleted)
                                  .WhereHasName_Canonized(artistTextQuery)
                                  .WhereHasTags(tagIds, childTags)
                                  .WhereHasTags(tags)
                                  .WhereStatusIs(status);

                var artistNames = artistQuery
                                  .OrderBy(sort, lang)
                                  .Take(start + maxResults)
                                  .SelectEntryBase(lang, EntryType.Artist)
                                  .ToArray();

                var albumQuery = ctx.OfType <Album>().Query()
                                 .Where(a => !a.Deleted)
                                 .WhereHasName(textQuery)
                                 .WhereHasTags(tagIds, childTags)
                                 .WhereHasTags(tags)
                                 .WhereStatusIs(status);

                var albumNames = albumQuery
                                 .OrderBy(sort, lang)
                                 .Take(start + maxResults)
                                 .SelectEntryBase(lang, EntryType.Album)
                                 .ToArray();

                var songQuery = ctx.OfType <Song>().Query()
                                .Where(a => !a.Deleted)
                                .WhereHasName(textQuery)
                                .WhereHasTags(tagIds, childTags)
                                .WhereHasTags(tags)
                                .WhereStatusIs(status);

                var songNames = songQuery
                                .OrderBy(sort, lang)
                                .Take(start + maxResults)
                                .SelectEntryBase(lang, EntryType.Song)
                                .ToArray();

                var tagQuery = searchTags ? ctx.OfType <Tag>().Query()
                               .WhereHasName(textQuery)
                               .WhereStatusIs(status) : null;

                var tagNames = searchTags ? tagQuery
                               .OrderBy(sort, lang)
                               .Take(start + maxResults)
                               .SelectEntryBase(lang, EntryType.Tag)
                               .ToArray() : null;

                // Get page of combined names
                var entryNames = artistNames.Concat(albumNames).Concat(songNames).Concat(tagNames ?? new DataContracts.EntryBaseContract[0])
                                 .OrderBy(e => e.DefaultName)
                                 .Skip(start)
                                 .Take(maxResults)
                                 .ToArray();

                var artistIds = entryNames.Where(e => e.EntryType == EntryType.Artist).Select(a => a.Id).ToArray();
                var albumIds = entryNames.Where(e => e.EntryType == EntryType.Album).Select(a => a.Id).ToArray();
                var songIds = entryNames.Where(e => e.EntryType == EntryType.Song).Select(a => a.Id).ToArray();
                var searchedTagIds = searchTags ? entryNames.Where(e => e.EntryType == EntryType.Tag).Select(a => a.Id).ToArray() : new int[0];

                // Get the actual entries in the page
                var artists = artistIds.Any() ? ctx.OfType <Artist>().Query()
                              .Where(a => artistIds.Contains(a.Id))
                              .ToArray()
                              .Select(a => new EntryForApiContract(a, lang, entryThumbPersister, ssl, fields)) : new EntryForApiContract[0];

                var albums = albumIds.Any() ? ctx.OfType <Album>().Query()
                             .Where(a => albumIds.Contains(a.Id))
                             .ToArray()
                             .Select(a => new EntryForApiContract(a, lang, entryThumbPersister, ssl, fields)) : new EntryForApiContract[0];

                var songs = songIds.Any() ? ctx.OfType <Song>().Query()
                            .Where(a => songIds.Contains(a.Id))
                            .ToArray()
                            .Select(a => new EntryForApiContract(a, lang, fields)) : new EntryForApiContract[0];

                var searchedTags = searchTags && searchedTagIds.Any() ? ctx.OfType <Tag>().Query()
                                   .Where(a => searchedTagIds.Contains(a.Id))
                                   .ToArray()
                                   .Select(a => new EntryForApiContract(a, lang, entryImagePersisterOld, ssl, fields)) : new EntryForApiContract[0];

                // Merge and sort the final list
                var entries = artists.Concat(albums).Concat(songs).Concat(searchedTags);

                if (sort == EntrySortRule.Name)
                {
                    entries = entries.OrderBy(a => a.Name);
                }

                if (sort == EntrySortRule.AdditionDate)
                {
                    entries = entries.OrderByDescending(a => a.CreateDate);
                }

                var count = 0;

                if (getTotalCount)
                {
                    var artistCount =
                        (artistNames.Length >= maxResults ? artistQuery.Count() : artistNames.Length);

                    var albumCount =
                        (albumNames.Length >= maxResults ? albumQuery.Count() : albumNames.Length);

                    var songCount =
                        (songNames.Length >= maxResults ? songQuery.Count() : songNames.Length);

                    var tagCount =
                        searchTags ? (tagNames.Length >= maxResults ? tagQuery.Count() : tagNames.Length) : 0;

                    count = artistCount + albumCount + songCount + tagCount;
                }

                return new PartialFindResult <EntryForApiContract>(entries.ToArray(), count);
            }));
        }
Ejemplo n.º 54
0
 public string[] GetNames(string query = "", NameMatchMode nameMatchMode = NameMatchMode.Auto, int maxResults = 15) => _service.FindNames(ArtistSearchTextQuery.Create(query, nameMatchMode), maxResults);
Ejemplo n.º 55
0
        private IQueryable <Tag> CreateQuery(TagQueryParams queryParams, string queryText, NameMatchMode nameMatchMode)
        {
            var textQuery = TagSearchTextQuery.Create(queryText, nameMatchMode);

            var query = dbContext.Query()
                        .WhereIsDeleted(false)
                        .WhereHasName(textQuery)
                        .WhereAllowChildren(queryParams.AllowChildren)
                        .WhereHasCategoryName(queryParams.CategoryName)
                        .WhereHasTarget(queryParams.Target);

            return(query);
        }
Ejemplo n.º 56
0
 public PartialFindResult<AlbumContract> FindAlbums(string term, int maxResults, 
     NameMatchMode nameMatchMode = NameMatchMode.Auto, AlbumSortRule sort = AlbumSortRule.NameThenReleaseDate)
 {
     return Services.Albums.Find(term, DiscType.Unknown, 0, maxResults, false, true, moveExactToTop: true, nameMatchMode: nameMatchMode, sortRule: sort);
 }