Beispiel #1
0
        public async Task <YVideoCollection> SearchAsync(long userId, string searchString, int pageSize, int pageNumber, string relatedTo = null, VideoSearchType videoSearchType = VideoSearchType.Videos)
        {
            var result = new YVideoCollection();

            using (var db = new DbRepository())
            {
                var m           = new YManager();
                var videoResult = $"{searchString}, -\"Playlist\"";

                var albumResult = $"{searchString}, +\"Albums\", \"Playlist\"";

                var playListResult = $"{searchString}, +\"Playlist\"";
                if (videoSearchType == VideoSearchType.Videos || videoSearchType == VideoSearchType.All || videoSearchType == VideoSearchType.Mix)
                {
                    result.Videos.AddRange(await m.SearchAsync(videoResult, relatedTo, videoSearchType != VideoSearchType.Mix ? VideoSearchType.Videos : videoSearchType, pageNumber, pageSize));
                }

                if (videoSearchType == VideoSearchType.Recommendation)
                {
                    var search           = new List <string>();
                    var userSearchedItem = db.Get <UserSearch>().Where(x => x.User_Id == userId).OrderByDescending(x => x.Counter).Take(1).ExecuteFirstOrDefault();
                    if (userSearchedItem != null)
                    {
                        search.Add(userSearchedItem.Text);
                    }
                    userSearchedItem = db.Get <UserSearch>().Where(x => x.User_Id != userId).OrderByDescending(x => x.Counter).Take(userSearchedItem == null ? 2 : 1).ExecuteFirstOrDefault();
                    if (userSearchedItem != null)
                    {
                        search.Add(userSearchedItem.Text);
                    }

                    result.Videos.AddRange(await m.SearchAsync($"{string.Join("|", search)} , +\"Albums\", \"Playlist\"", relatedTo, videoSearchType, pageNumber, pageSize));
                }

                if (string.IsNullOrEmpty(relatedTo))
                {
                    if (videoSearchType == VideoSearchType.Album || videoSearchType == VideoSearchType.All)
                    {
                        result.Albums.AddRange(await m.SearchAsync(albumResult, relatedTo, VideoSearchType.Album, pageNumber, pageSize));
                    }

                    if (videoSearchType == VideoSearchType.PlayList || videoSearchType == VideoSearchType.All)
                    {
                        result.Playlists.AddRange(await m.SearchAsync(playListResult, relatedTo, VideoSearchType.PlayList, pageNumber, pageSize));
                    }
                }

                if (!string.IsNullOrEmpty(searchString) && result.Videos.Any() && videoSearchType != VideoSearchType.Recommendation)
                {
                    var item = db.Get <UserSearch>().Where(x => x.Text.Contains(searchString) && x.User_Id == userId).ExecuteFirstOrDefault() ?? new UserSearch()
                    {
                        Text = searchString, User_Id = userId
                    };
                    item.Counter = (item.Counter ?? 0) + 1;
                    db.Save(item).SaveChanges();
                }
            }
            return(result);
        }
Beispiel #2
0
        public static List <VideoWrapper> ToItemList(this YVideoCollection items)
        {
            var result = new List <VideoWrapper>();

            result.AddRange(items.Videos);
            result.AddRange(items.Playlists);
            result.AddRange(items.Albums);
            return(result);
        }
 public SearchView(YVideoCollection videos, string text)
 {
     InitializeComponent();
     _videos = videos;
     stVideoContainer.HeaderIsVisible = _videos.Playlists.Any();
     lstAlbums.HeaderIsVisible        = _videos.Albums.Any();
     stVideoContainer.HeaderIsVisible = _videos.Videos.Any();
     textSearch = text;
     this.AddTrigger(
         ControllerRepository.GetInfo <IDbController, Task>(x => x.SaveCategory(null)),
         ControllerRepository.GetInfo <IDbController, Task>(x => x.SaveVideo(null)));
 }
Beispiel #4
0
        public async Task <SearchResult> DataBind()
        {
            var l = await this.StartLoading();

            _videos = ControllerRepository.Y(x => x.SearchAsync(UserData.CurrentUser.EntityId.Value, _searchfor, 20, 1, null, _videoSearchType)).Await();
            if (_videoSearchType == VideoSearchType.Album)
            {
                stVideoContainer.SourceItems = _videos.Albums;
            }
            else if (_videoSearchType == VideoSearchType.PlayList)
            {
                stVideoContainer.SourceItems = _videos.Playlists;
            }
            else
            {
                stVideoContainer.SourceItems = _videos.Videos;
            }
            l.EndLoading();
            return(this);
        }