From de133cb8aa2b078ba653ee7c3e1cef4fd16996d6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 21 Aug 2015 22:59:10 -0400 Subject: [PATCH] update search --- MediaBrowser.Controller/Entities/BaseItem.cs | 1 + .../LiveTv/LiveTvProgram.cs | 6 + MediaBrowser.Controller/LiveTv/ProgramInfo.cs | 5 + .../Library/SearchEngine.cs | 284 ++++++------------ .../Library/Validators/GameGenresValidator.cs | 27 +- .../Library/Validators/GenresValidator.cs | 27 +- .../Validators/MusicGenresValidator.cs | 28 +- .../Library/Validators/StudiosValidator.cs | 28 +- .../LiveTv/EmbyTV/EmbyTV.cs | 18 +- .../LiveTv/Listings/SchedulesDirect.cs | 5 +- .../LiveTv/LiveTvManager.cs | 9 +- .../Api/PackageCreator.cs | 2 +- .../MediaBrowser.WebDashboard.csproj | 18 +- 13 files changed, 230 insertions(+), 228 deletions(-) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index c4917b0d1f..cd5c391730 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -485,6 +485,7 @@ namespace MediaBrowser.Controller.Entities /// Gets or sets the parent. /// /// The parent. + [IgnoreDataMember] public Folder Parent { get diff --git a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs index 14944d36fa..12052905f2 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs @@ -30,6 +30,12 @@ namespace MediaBrowser.Controller.LiveTv return GetClientTypeName() + "-" + Name; } + /// + /// Gets or sets the etag. + /// + /// The etag. + public string Etag { get; set; } + /// /// Id of the program. /// diff --git a/MediaBrowser.Controller/LiveTv/ProgramInfo.cs b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs index 467264e7ab..a6a3e61081 100644 --- a/MediaBrowser.Controller/LiveTv/ProgramInfo.cs +++ b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs @@ -180,6 +180,11 @@ namespace MediaBrowser.Controller.LiveTv /// /// The episode number. public int? EpisodeNumber { get; set; } + /// + /// Gets or sets the etag. + /// + /// The etag. + public string Etag { get; set; } public ProgramInfo() { diff --git a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs index 21e92786d0..d4ff89b4f5 100644 --- a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs @@ -33,26 +33,17 @@ namespace MediaBrowser.Server.Implementations.Library public async Task> GetSearchHints(SearchQuery query) { - IEnumerable inputItems; - - Func filter = i => !(i is ICollectionFolder); - User user = null; if (string.IsNullOrWhiteSpace(query.UserId)) { - inputItems = _libraryManager.RootFolder.GetRecursiveChildren(filter); } else { user = _userManager.GetUserById(query.UserId); - - inputItems = user.RootFolder.GetRecursiveChildren(user, filter); } - inputItems = _libraryManager.ReplaceVideosWithPrimaryVersions(inputItems); - - var results = await GetSearchHints(inputItems, query, user).ConfigureAwait(false); + var results = await GetSearchHints(query, user).ConfigureAwait(false); var searchResultArray = results.ToArray(); results = searchResultArray; @@ -77,15 +68,22 @@ namespace MediaBrowser.Server.Implementations.Library }; } + private void AddIfMissing(List list, string value) + { + if (!list.Contains(value, StringComparer.OrdinalIgnoreCase)) + { + list.Add(value); + } + } + /// /// Gets the search hints. /// - /// The input items. /// The query. /// The user. /// IEnumerable{SearchHintResult}. /// searchTerm - private Task> GetSearchHints(IEnumerable inputItems, SearchQuery query, User user) + private Task> GetSearchHints(SearchQuery query, User user) { var searchTerm = query.SearchTerm; @@ -100,207 +98,80 @@ namespace MediaBrowser.Server.Implementations.Library var hints = new List>(); - var items = inputItems.Where(i => !(i is MusicArtist)).ToList(); + var excludeItemTypes = new List(); + var includeItemTypes = (query.IncludeItemTypes ?? new string[] { }).ToList(); - if (query.IncludeMedia) + excludeItemTypes.Add(typeof(Year).Name); + + if (query.IncludeGenres && (includeItemTypes.Count == 0 || includeItemTypes.Contains("Genre", StringComparer.OrdinalIgnoreCase))) { - var mediaItems = _libraryManager.GetItems(new InternalItemsQuery + if (!query.IncludeMedia) { - NameContains = searchTerm, - ExcludeItemTypes = new[] - { - typeof (Person).Name, - typeof (Genre).Name, - typeof (MusicArtist).Name, - typeof (GameGenre).Name, - typeof (MusicGenre).Name, - typeof (Year).Name, - typeof (Studio).Name - }, - IncludeItemTypes = query.IncludeItemTypes - - }).Items; - - // Add search hints based on item name - hints.AddRange(mediaItems.Where(i => IncludeInSearch(i) && (user == null || i.IsVisibleStandalone(user)) && !(i is CollectionFolder)).Select(item => - { - var index = GetIndex(item.Name, searchTerm, terms); - - return new Tuple(item, index.Item1, index.Item2); - })); - } - - if (query.IncludeArtists && (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains("MusicArtist", StringComparer.OrdinalIgnoreCase))) - { - // Find artists - var artists = items.OfType