jellyfin/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs

33 lines
1.1 KiB
C#
Raw Normal View History

2013-03-28 22:00:58 +00:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Library
{
/// <summary>
/// Class LuceneSearchEngine
/// http://www.codeproject.com/Articles/320219/Lucene-Net-ultra-fast-search-for-MVC-or-WebForms
/// </summary>
public class LuceneSearchEngine : ILibrarySearchEngine
{
/// <summary>
2013-03-28 22:08:04 +00:00
/// Searches items and returns them in order of relevance.
2013-03-28 22:00:58 +00:00
/// </summary>
/// <param name="items">The items.</param>
/// <param name="searchTerm">The search term.</param>
/// <returns>IEnumerable{BaseItem}.</returns>
/// <exception cref="System.ArgumentNullException">searchTerm</exception>
public IEnumerable<BaseItem> Search(IEnumerable<BaseItem> items, string searchTerm)
{
if (string.IsNullOrEmpty(searchTerm))
{
throw new ArgumentNullException("searchTerm");
}
2013-04-10 19:25:06 +00:00
return items.Where(i => i.Name.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) != -1);
2013-03-28 22:00:58 +00:00
}
}
}