using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; 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, IDisposable { private readonly ILibraryManager _libraryManager; private readonly ILogger _logger; public LuceneSearchEngine(IServerApplicationPaths serverPaths, ILogManager logManager, ILibraryManager libraryManager) { _libraryManager = libraryManager; _logger = logManager.GetLogger("Lucene"); } /// /// Searches items and returns them in order of relevance. /// /// The items. /// The search term. /// IEnumerable{BaseItem}. /// searchTerm public IEnumerable Search(IEnumerable items, string searchTerm) { return items; } public void Dispose() { //BaseItem.LibraryManager.LibraryChanged -= LibraryChanged; //LuceneSearch.CloseAll(); } /// /// Gets the search hints. /// /// The input items. /// The search term. /// IEnumerable{SearchHintResult}. /// searchTerm public Task> GetSearchHints(IEnumerable inputItems, string searchTerm) { if (string.IsNullOrEmpty(searchTerm)) { throw new ArgumentNullException("searchTerm"); } var terms = GetWords(searchTerm); var hints = new List>(); var items = inputItems.Where(i => !(i is MusicArtist)).ToList(); // Add search hints based on item name hints.AddRange(items.Where(i => !string.IsNullOrEmpty(i.Name)).Select(item => { var index = GetIndex(item.Name, searchTerm, terms); return new Tuple(item, index.Item1, index.Item2); })); // Find artists var artists = items.OfType