diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 66822d8528..939a173149 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -122,15 +122,19 @@ namespace MediaBrowser.Api.UserLibrary /// The _library manager /// private readonly ILibraryManager _libraryManager; + private readonly ILibrarySearchEngine _searchEngine; /// /// Initializes a new instance of the class. /// /// The user manager. - public ItemsService(IUserManager userManager, ILibraryManager libraryManager) + /// The library manager. + /// The search engine. + public ItemsService(IUserManager userManager, ILibraryManager libraryManager, ILibrarySearchEngine searchEngine) { _userManager = userManager; _libraryManager = libraryManager; + _searchEngine = searchEngine; } /// @@ -400,7 +404,7 @@ namespace MediaBrowser.Api.UserLibrary if (!string.IsNullOrEmpty(term)) { - items = _libraryManager.Search(items, request.SearchTerm); + items = _searchEngine.Search(items, request.SearchTerm); } return items; diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index a69e064604..84a39db691 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -174,14 +174,6 @@ namespace MediaBrowser.Controller.Library IEnumerable Sort(IEnumerable items, User user, IEnumerable sortBy, SortOrder sortOrder); - /// - /// Sorts the specified items. - /// - /// The items. - /// The search term. - /// IEnumerable{BaseItem}. - IEnumerable Search(IEnumerable items, string searchTerm); - /// /// Ensure supplied item has only one instance throughout /// diff --git a/MediaBrowser.Controller/Library/ILibrarySearchEngine.cs b/MediaBrowser.Controller/Library/ILibrarySearchEngine.cs new file mode 100644 index 0000000000..082ebf7b3e --- /dev/null +++ b/MediaBrowser.Controller/Library/ILibrarySearchEngine.cs @@ -0,0 +1,19 @@ +using MediaBrowser.Controller.Entities; +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Library +{ + /// + /// Interface ILibrarySearchEngine + /// + public interface ILibrarySearchEngine + { + /// + /// Sorts the specified items. + /// + /// The items. + /// The search term. + /// IEnumerable{BaseItem}. + IEnumerable Search(IEnumerable items, string searchTerm); + } +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index ba9812d337..02f15b94ab 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -88,6 +88,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index bf21e75004..cf12d6ad57 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -817,21 +817,5 @@ namespace MediaBrowser.Server.Implementations.Library return comparer; } - - /// - /// Sorts the specified items. - /// - /// The items. - /// The search term. - /// IEnumerable{BaseItem}. - public IEnumerable Search(IEnumerable items, string searchTerm) - { - if (string.IsNullOrEmpty(searchTerm)) - { - throw new ArgumentNullException("searchTerm"); - } - - return items.Where(i => i.Name.StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase)); - } } } diff --git a/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs b/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs new file mode 100644 index 0000000000..e0e5c3541d --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs @@ -0,0 +1,32 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Server.Implementations.Library +{ + /// + /// Class LuceneSearchEngine + /// http://www.codeproject.com/Articles/320219/Lucene-Net-ultra-fast-search-for-MVC-or-WebForms + /// + public class LuceneSearchEngine : ILibrarySearchEngine + { + /// + /// Sorts the specified items. + /// + /// The items. + /// The search term. + /// IEnumerable{BaseItem}. + /// searchTerm + public IEnumerable Search(IEnumerable items, string searchTerm) + { + if (string.IsNullOrEmpty(searchTerm)) + { + throw new ArgumentNullException("searchTerm"); + } + + return items.Where(i => i.Name.StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase)); + } + } +} diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 9aac84f29f..90ab86fe4f 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -125,6 +125,7 @@ + diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 7c43b9293e..131d0a7e7f 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -212,6 +212,8 @@ namespace MediaBrowser.ServerApplication ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, DirectoryWatchers, LogManager); RegisterSingleInstance(ProviderManager); + RegisterSingleInstance(() => new LuceneSearchEngine()); + SetKernelProperties(); SetStaticProperties(); } diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index cc71d5df66..0d66258724 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -119,10 +119,16 @@ ..\packages\Hardcodet.Wpf.TaskbarNotification.1.0.4.0\lib\net40\Hardcodet.Wpf.TaskbarNotification.dll + + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + False ..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll + + ..\packages\Lucene.Net.3.0.3\lib\NET40\Lucene.Net.dll + False ..\packages\MediaBrowser.IsoMounting.3.0.51\lib\net45\MediaBrowser.IsoMounter.dll diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config index 1dcbfc4c0f..43836635f2 100644 --- a/MediaBrowser.ServerApplication/packages.config +++ b/MediaBrowser.ServerApplication/packages.config @@ -2,10 +2,12 @@ + + \ No newline at end of file