From 0bfb755a3895d26144a69eb7f0ea02bba655a15f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 27 Apr 2013 09:05:33 -0400 Subject: [PATCH] search hints progress --- MediaBrowser.Api/SearchService.cs | 45 +++-- MediaBrowser.Controller/Dto/DtoBuilder.cs | 2 +- .../Entities/Audio/Audio.cs | 12 ++ .../Entities/Audio/MusicAlbum.cs | 14 +- .../Library/ILibrarySearchEngine.cs | 4 +- .../Library/SearchHintInfo.cs | 22 +++ .../MediaBrowser.Controller.csproj | 1 + .../MediaInfo/FFProbeAudioInfoProvider.cs | 6 +- .../Providers/Music/LastfmAlbumProvider.cs | 2 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + MediaBrowser.Model/Search/SearchHint.cs | 106 ++++++++++++ MediaBrowser.Model/Search/SearchHintResult.cs | 69 +------- .../Library/LuceneSearchEngine.cs | 162 ++++++++++++------ .../MediaBrowser.WebDashboard.csproj | 15 ++ 14 files changed, 334 insertions(+), 127 deletions(-) create mode 100644 MediaBrowser.Controller/Library/SearchHintInfo.cs create mode 100644 MediaBrowser.Model/Search/SearchHint.cs diff --git a/MediaBrowser.Api/SearchService.cs b/MediaBrowser.Api/SearchService.cs index a3d228529..d8aad5283 100644 --- a/MediaBrowser.Api/SearchService.cs +++ b/MediaBrowser.Api/SearchService.cs @@ -20,7 +20,7 @@ namespace MediaBrowser.Api /// [Route("/Search/Hints", "GET")] [Api(Description = "Gets search hints based on a search term")] - public class GetSearchHints : IReturn> + public class GetSearchHints : IReturn { /// /// Skips over a given number of items within the results. Use for paging. @@ -96,7 +96,7 @@ namespace MediaBrowser.Api /// /// The request. /// Task{IEnumerable{SearchHintResult}}. - private async Task> GetSearchHintsAsync(GetSearchHints request) + private async Task GetSearchHintsAsync(GetSearchHints request) { IEnumerable inputItems; @@ -113,34 +113,48 @@ namespace MediaBrowser.Api var results = await _searchEngine.GetSearchHints(inputItems, request.SearchTerm).ConfigureAwait(false); + var searchResultArray = results.ToArray(); + + IEnumerable returnResults = searchResultArray; + if (request.StartIndex.HasValue) { - results = results.Skip(request.StartIndex.Value); + returnResults = returnResults.Skip(request.StartIndex.Value); } if (request.Limit.HasValue) { - results = results.Take(request.Limit.Value); + returnResults = returnResults.Take(request.Limit.Value); } - return results.Select(GetSearchHintResult); + return new SearchHintResult + { + TotalRecordCount = searchResultArray.Length, + + SearchHints = returnResults.Select(GetSearchHintResult).ToArray() + }; } /// /// Gets the search hint result. /// - /// The item. + /// The hint info. /// SearchHintResult. - private SearchHintResult GetSearchHintResult(BaseItem item) + private SearchHint GetSearchHintResult(SearchHintInfo hintInfo) { - var result = new SearchHintResult + var item = hintInfo.Item; + + var result = new SearchHint { Name = item.Name, IndexNumber = item.IndexNumber, ParentIndexNumber = item.ParentIndexNumber, ItemId = DtoBuilder.GetClientItemId(item), Type = item.GetType().Name, - MediaType = item.MediaType + MediaType = item.MediaType, + MatchedTerm = hintInfo.MatchedTerm, + DisplayMediaType = item.DisplayMediaType, + RunTimeTicks = item.RunTimeTicks }; if (item.HasImage(ImageType.Primary)) @@ -160,14 +174,25 @@ namespace MediaBrowser.Api if (season != null) { result.Series = season.Series.Name; + + result.EpisodeCount = season.RecursiveChildren.OfType().Count(); + } + + var series = item as Series; + + if (series != null) + { + result.EpisodeCount = series.RecursiveChildren.OfType().Count(); } var album = item as MusicAlbum; if (album != null) { - var songs = album.Children.OfType