From 1d6f82e2eff578dc1ff075bfd01aec16fde7c857 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 14 Feb 2016 12:58:31 -0500 Subject: [PATCH] update search results --- .../Entities/InternalItemsQuery.cs | 1 + .../Library/LibraryManager.cs | 2 +- .../Library/SearchEngine.cs | 1 + .../LiveTv/LiveTvManager.cs | 9 +++++-- .../Persistence/SqliteItemRepository.cs | 26 +++++++++++++++---- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 96cd305a6..0595d0569 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -27,6 +27,7 @@ namespace MediaBrowser.Controller.Entities public bool? IsLiked { get; set; } public bool? IsPlayed { get; set; } public bool? IsResumable { get; set; } + public bool? IncludeItemsByName { get; set; } public string[] MediaTypes { get; set; } public string[] IncludeItemTypes { get; set; } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index e4cb58346..333b1fbe9 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1324,7 +1324,7 @@ namespace MediaBrowser.Server.Implementations.Library SetTopParentIdsOrAncestors(query, parents); - return GetItemIds(query).Select(GetItemById); + return GetItemIds(query).Select(GetItemById).Where(i => i != null); } public QueryResult GetItemsResult(InternalItemsQuery query, IEnumerable parentIds) diff --git a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs index aff982b0d..62392c1c7 100644 --- a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs @@ -163,6 +163,7 @@ namespace MediaBrowser.Server.Implementations.Library ExcludeItemTypes = excludeItemTypes.ToArray(), IncludeItemTypes = includeItemTypes.ToArray(), Limit = query.Limit, + IncludeItemsByName = true }, new string[] { }); diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 85b2059ae..14bfcba27 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -300,6 +300,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv public async Task GetInternalRecording(string id, CancellationToken cancellationToken) { + if (string.IsNullOrWhiteSpace(id)) + { + throw new ArgumentNullException("id"); + } + var result = await GetInternalRecordings(new RecordingQuery { Id = id @@ -1410,7 +1415,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var queryResult = _libraryManager.GetItems(internalQuery, new string[] { }); IEnumerable recordings = queryResult.Cast(); - if (!string.IsNullOrEmpty(query.Id)) + if (!string.IsNullOrWhiteSpace(query.Id)) { var guid = new Guid(query.Id); @@ -1418,7 +1423,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv .Where(i => i.Id == guid); } - if (!string.IsNullOrEmpty(query.GroupId)) + if (!string.IsNullOrWhiteSpace(query.GroupId)) { var guid = new Guid(query.GroupId); diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index d7bf294e3..346dcf359 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1914,18 +1914,34 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add("LocationType not in (" + val + ")"); } + var enableItemsByName = query.IncludeItemsByName ?? query.IncludeItemTypes.Length > 0; + if (query.TopParentIds.Length == 1) { - whereClauses.Add("(TopParentId=@TopParentId or IsItemByName=@IsItemByName)"); + if (enableItemsByName) + { + whereClauses.Add("(TopParentId=@TopParentId or IsItemByName=@IsItemByName)"); + cmd.Parameters.Add(cmd, "@IsItemByName", DbType.Boolean).Value = true; + } + else + { + whereClauses.Add("(TopParentId=@TopParentId)"); + } cmd.Parameters.Add(cmd, "@TopParentId", DbType.String).Value = query.TopParentIds[0]; - cmd.Parameters.Add(cmd, "@IsItemByName", DbType.Boolean).Value = true; } if (query.TopParentIds.Length > 1) { var val = string.Join(",", query.TopParentIds.Select(i => "'" + i + "'").ToArray()); - - whereClauses.Add("(IsItemByName=@IsItemByName or TopParentId in (" + val + "))"); - cmd.Parameters.Add(cmd, "@IsItemByName", DbType.Boolean).Value = true; + + if (enableItemsByName) + { + whereClauses.Add("(IsItemByName=@IsItemByName or TopParentId in (" + val + "))"); + cmd.Parameters.Add(cmd, "@IsItemByName", DbType.Boolean).Value = true; + } + else + { + whereClauses.Add("(TopParentId in (" + val + "))"); + } } if (query.AncestorIds.Length == 1)