public void ParseTextQuery_DateRange() { var result = songSearch.ParseTextQuery(SearchTextQuery.Create("publish-date:2015/9/3-2015/10/1")); Assert.AreEqual(new DateTime(2015, 9, 3), result.PublishedAfter, "Publish date after"); Assert.AreEqual(new DateTime(2015, 10, 1), result.PublishedBefore, "Publish date before"); }
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 void ParseTextQuery_Id() { var result = songSearch.ParseTextQuery(SearchTextQuery.Create("id:3939")); Assert.IsFalse(result.HasNameQuery, "HasNameQuery"); Assert.AreEqual(3939, result.Id, "Id query"); }
public ActionResult Index(string filter = null, UserGroupId?groupId = null) { var vm = new Models.User.Index { Filter = filter, GroupId = groupId }; if (!string.IsNullOrEmpty(filter)) { var queryParams = new UserQueryParams { Common = new CommonSearchParams(SearchTextQuery.Create(filter), false, false), Paging = new PagingProperties(0, 1, true), Group = groupId ?? UserGroupId.Nothing }; var result = Data.GetUsers(queryParams, u => u.Name); if (result.TotalCount == 1 && result.Items.Length == 1) { return(RedirectToAction("Profile", new { id = result.Items[0] })); } } return(View(vm)); }
public T FindFirst <T>(Func <Song, ISession, 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 { TextQuery = SearchTextQuery.Create(q, nameMatchMode), OnlyByName = true, MoveExactToTop = true }, LanguagePreference = LanguagePreference, Paging = new PagingProperties(0, 30, false) }); if (result.Items.Any()) { return fac(result.Items.First(), session); } } return null; })); }
public LyricsForSongContract GetRandomLyricsForSong(string query) { return(HandleQuery(session => { var songContract = Find(session, new SongQueryParams(SearchTextQuery.Create(query), new SongType[] { }, 0, 10, false, SongSortRule.Name, false, true, null) { AdvancedFilters = new[] { new AdvancedSearchFilter { FilterType = AdvancedFilterType.Lyrics, Param = AdvancedSearchFilter.Any } } }).Items; if (!songContract.Any()) { return null; } var songIds = songContract.Select(s => s.Id).ToArray(); var songs = session.Query <Song>().Where(s => songIds.Contains(s.Id)).ToArray(); var allLyrics = songs.SelectMany(s => s.Lyrics).ToArray(); if (!allLyrics.Any()) { return null; } var lyrics = allLyrics[new Random().Next(allLyrics.Length)]; return new LyricsForSongContract(lyrics); })); }
public void ParseTextQuery_Name() { var result = songSearch.ParseTextQuery(SearchTextQuery.Create("Hatsune Miku")); Assert.IsTrue(result.HasNameQuery, "HasNameQuery"); Assert.AreEqual("Hatsune Miku", result.Name.Query, "Name query"); }
public PartialFindResult <UserForApiContract> GetList( string query = "", UserGroupId groups = UserGroupId.Nothing, DateTime?joinDateAfter = null, DateTime?joinDateBefore = null, NameMatchMode nameMatchMode = NameMatchMode.Auto, int start = 0, int maxResults = 10, bool getTotalCount = false, UserSortRule?sort = null, bool includeDisabled = false, bool onlyVerified = false, string knowsLanguage = null, UserOptionalFields fields = UserOptionalFields.None) { var queryParams = new UserQueryParams { Common = new CommonSearchParams(SearchTextQuery.Create(query, nameMatchMode), false, false), Group = groups, IncludeDisabled = includeDisabled, OnlyVerifiedArtists = onlyVerified, KnowsLanguage = knowsLanguage, JoinDateAfter = joinDateAfter, JoinDateBefore = joinDateBefore, Sort = sort ?? UserSortRule.Name, Paging = new PagingProperties(start, maxResults, getTotalCount) }; return(queries.GetUsers(queryParams, user => new UserForApiContract(user, userIconFactory, fields))); }
private IQueryable <Song> CreateQuery( SongQueryParams queryParams, ParsedSongQuery parsedQuery, NameMatchMode?nameMatchMode = null) { var textQuery = SearchTextQuery.Create(parsedQuery.Name, nameMatchMode ?? queryParams.Common.NameMatchMode); var query = Query <Song>() .Where(s => !s.Deleted) .WhereHasName(textQuery) .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) .WhereHasPVService(queryParams.PVServices) .WhereIdIs(parsedQuery.Id) .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); }
public PartialFindResult <SongInListForApiContract> GetSongs(int listId, string query = "", string songTypes = null, PVServices?pvServices = null, [FromQuery(Name = "tagId[]")] int[] tagId = null, [FromQuery(Name = "artistId[]")] int[] artistId = null, bool childVoicebanks = false, [FromQuery(Name = "advancedFilters")] AdvancedSearchFilterParams[] advancedFilters = null, 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); var types = EnumVal <SongType> .ParseMultiple(songTypes); return(_queries.GetSongsInList( new SongInListQueryParams { TextQuery = SearchTextQuery.Create(query, nameMatchMode), ListId = listId, Paging = new PagingProperties(start, maxResults, getTotalCount), PVServices = pvServices, ArtistIds = artistId, ChildVoicebanks = childVoicebanks, TagIds = tagId, SortRule = sort, AdvancedFilters = advancedFilters?.Select(advancedFilter => advancedFilter.ToAdvancedSearchFilter()).ToArray(), SongTypes = types, }, songInList => new SongInListForApiContract(songInList, lang, fields))); }
public UserContract GetUserInfo(string name) { var users = userQueries.GetUsers(SearchTextQuery.Create(name, NameMatchMode.Exact), UserGroupId.Nothing, false, false, null, UserSortRule.Name, new PagingProperties(0, 1, false), u => new UserContract(u)); return(users.Items.FirstOrDefault()); }
public FeedResult Feed(IndexRouteParams indexParams) { WebHelper.VerifyUserAgent(Request); var pageSize = (indexParams.pageSize.HasValue ? Math.Min(indexParams.pageSize.Value, 30) : 30); var sortRule = indexParams.sort ?? SongSortRule.Name; var timeFilter = DateTimeUtils.ParseFromSimpleString(indexParams.since); var filter = indexParams.filter; var songType = indexParams.songType ?? SongType.Unspecified; var matchMode = indexParams.matchMode ?? NameMatchMode.Auto; var onlyWithPVs = indexParams.onlyWithPVs ?? false; var minScore = indexParams.minScore ?? 0; var textQuery = SearchTextQuery.Create(filter, matchMode); var queryParams = new SongQueryParams(textQuery, songType != SongType.Unspecified ? new[] { songType } : new SongType[] { }, 0, pageSize, false, sortRule, false, false, null) { TimeFilter = timeFilter, OnlyWithPVs = onlyWithPVs, ArtistIds = !indexParams.artistId.HasValue || indexParams.artistId.Value == 0 ? null : new [] { indexParams.artistId.Value }, MinScore = minScore, }; var result = Service.FindWithThumbPreferNotNico(queryParams); var fac = new SongFeedFactory(); var feed = fac.Create(result.Items, VocaUriBuilder.CreateAbsolute(Url.Action("Index", indexParams)), song => RenderPartialViewToString("SongItem", song), song => Url.Action("Details", new { id = song.Id })); return(new FeedResult(new Atom10FeedFormatter(feed))); }
public void Find_NameWords() { queryParams.Common.TextQuery = SearchTextQuery.Create("Anger"); var result = CallFind(); AssertTags(result, "Anger", "Anger [EXTEND RMX]"); }
/// <summary> /// Filters query by one or more tag names. /// The tag has to match at least one of the names. /// For empty list of names (or null) nothing is matched. /// The name has to be exact match (case insensitive). /// </summary> /// <param name="query">Query to be filtered. Cannot be null.</param> /// <param name="names">List of names to filter by. Can be null or empty, but in that case no tags will be matched.</param> /// <returns>Filtered query. Cannot be null.</returns> public static IQueryable <Tag> WhereHasName(this IQueryable <Tag> query, params string[] names) { names = names ?? new string[0]; var queries = names.Select(n => SearchTextQuery.Create(n, NameMatchMode.Exact)); return(query.WhereHasNameGeneric <Tag, TagName>(queries)); }
public PartialFindResult <ReleaseEventSeriesContract> GetList( string query = "", int start = 0, int maxResults = defaultMax, bool getTotalCount = false, NameMatchMode nameMatchMode = NameMatchMode.Auto) { return(queries.FindSeries(s => new ReleaseEventSeriesContract(s), SearchTextQuery.Create(query, nameMatchMode), new PagingProperties(start, maxResults, getTotalCount))); }
public void Find_NameQuotedExact() { queryParams.Common.TextQuery = SearchTextQuery.Create("\"Anger\""); var result = CallFind(); AssertTags(result, "Anger"); }
public void Find_NameMatchModeExact() { queryParams.Common.TextQuery = SearchTextQuery.Create("Anger", NameMatchMode.Exact); var result = CallFind(); AssertTags(result, "Anger"); }
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)); }
public void QueryNameMoveExactToTop() { _queryParams = _queryParams with { Common = _queryParams.Common with { TextQuery = SearchTextQuery.Create("Tears"), MoveExactToTop = true, },
public PartialFindResult <SongForApiContract> GetList( string query = "", string songTypes = null, [FromUri] string[] tagName = null, [FromUri] int[] tagId = null, bool childTags = 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, 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 }, TagIds = tagId, Tags = tagName, ChildTags = childTags, OnlyWithPVs = onlyWithPvs, TimeFilter = since.HasValue ? TimeSpan.FromHours(since.Value) : TimeSpan.Zero, MinScore = minScore ?? 0, PVServices = pvServices, UserCollectionId = userCollectionId ?? 0, ReleaseEventId = releaseEventId ?? 0, AdvancedFilters = advancedFilters, LanguagePreference = lang }; param.Common.EntryStatus = status; var artists = service.Find(s => new SongForApiContract(s, null, lang, fields), param); return(artists); }
public PartialFindResult <ReleaseEventSeriesForApiContract> GetList( string query = "", ReleaseEventSeriesOptionalFields fields = ReleaseEventSeriesOptionalFields.None, int start = 0, int maxResults = defaultMax, bool getTotalCount = false, NameMatchMode nameMatchMode = NameMatchMode.Auto, ContentLanguagePreference lang = ContentLanguagePreference.Default) { return(queries.FindSeries(SearchTextQuery.Create(query, nameMatchMode), new PagingProperties(start, maxResults, getTotalCount), lang, fields)); }
public void QueryNameWords() { _queryParams.Common.TextQuery = SearchTextQuery.Create("Tears Crystal", NameMatchMode.Words); var result = CallFind(); result.Items.Length.Should().Be(1, "1 result"); result.TotalCount.Should().Be(1, "total result count"); result.Items[0].DefaultName.Should().Be("Crystal Tears"); }
public void QueryTag() { queryParams.Common.TextQuery = SearchTextQuery.Create("tag:Electronic"); var result = CallFind(); Assert.AreEqual(1, result.Items.Length, "1 result"); Assert.AreEqual(1, result.TotalCount, "1 total count"); Assert.AreEqual(Db.Song, result.Items[0], "result is as expected"); }
public void QueryNameWords() { queryParams.Common.TextQuery = SearchTextQuery.Create("Tears Crystal", NameMatchMode.Words); var result = CallFind(); Assert.AreEqual(1, result.Items.Length, "1 result"); Assert.AreEqual(1, result.TotalCount, "total result count"); Assert.AreEqual("Crystal Tears", result.Items[0].DefaultName); }
public void QueryTag() { _queryParams.Common.TextQuery = SearchTextQuery.Create("tag:Electronic"); var result = CallFind(); result.Items.Length.Should().Be(1, "1 result"); result.TotalCount.Should().Be(1, "1 total count"); result.Items[0].Should().Be(Db.Song, "result is as expected"); }
public void QueryName() { queryParams.Common.TextQuery = SearchTextQuery.Create("DIVINE"); var result = Find(); Assert.AreEqual(1, result.Items.Length, "1 result"); Assert.AreEqual(1, result.TotalCount, "total result count"); Assert.AreEqual("DIVINE", result.Items[0].DefaultName); }
public void QueryName() { _queryParams.Common.TextQuery = SearchTextQuery.Create("DIVINE"); var result = Find(); result.Items.Length.Should().Be(1, "1 result"); result.TotalCount.Should().Be(1, "total result count"); result.Items[0].DefaultName.Should().Be("DIVINE"); }
public void QueryNameWords_SkipFirstPage() { CreateName(_album, "Synthesis Miku", ContentLanguageSelection.Unspecified); CreateName(_albumWithArtist, "DIVINE Miku", ContentLanguageSelection.Unspecified); _queryParams = _queryParams with { Common = _queryParams.Common with { TextQuery = SearchTextQuery.Create("Miku Miku") },
public PartialFindResult <AlbumForApiContract> GetList( string query = "", DiscType discTypes = DiscType.Unknown, [FromUri] string[] tagName = null, [FromUri] int[] tagId = null, bool childTags = false, [FromUri] int[] artistId = null, ArtistAlbumParticipationStatus artistParticipationStatus = ArtistAlbumParticipationStatus.Everything, bool childVoicebanks = false, bool includeMembers = false, string barcode = null, EntryStatus?status = null, DateTime?releaseDateAfter = null, DateTime?releaseDateBefore = null, [FromUri] AdvancedSearchFilter[] advancedFilters = 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), getTotalCount, sort ?? AlbumSortRule.Name, preferAccurateMatches) { ArtistParticipation = { ArtistIds = artistId, Participation = artistParticipationStatus, ChildVoicebanks = childVoicebanks, IncludeMembers = includeMembers }, Tags = tagName, TagIds = tagId, ChildTags = childTags, Barcode = barcode, Deleted = deleted, ReleaseDateAfter = releaseDateAfter, ReleaseDateBefore = releaseDateBefore, AdvancedFilters = advancedFilters, LanguagePreference = lang }; queryParams.Common.EntryStatus = status; var ssl = WebHelper.IsSSL(Request); var entries = service.Find(a => new AlbumForApiContract(a, null, lang, thumbPersister, ssl, fields, SongOptionalFields.None), queryParams); return(entries); }
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); }