add live tv to search
This commit is contained in:
parent
b3de0249d8
commit
42542e10bf
|
@ -40,6 +40,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
public string NameStartsWithOrGreater { get; set; }
|
public string NameStartsWithOrGreater { get; set; }
|
||||||
public string NameStartsWith { get; set; }
|
public string NameStartsWith { get; set; }
|
||||||
public string NameLessThan { get; set; }
|
public string NameLessThan { get; set; }
|
||||||
|
public string NameContains { get; set; }
|
||||||
|
|
||||||
public string Person { get; set; }
|
public string Person { get; set; }
|
||||||
public string[] PersonIds { get; set; }
|
public string[] PersonIds { get; set; }
|
||||||
|
|
|
@ -37,26 +37,22 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
|
|
||||||
Func<BaseItem, bool> filter = i => !(i is ICollectionFolder);
|
Func<BaseItem, bool> filter = i => !(i is ICollectionFolder);
|
||||||
|
|
||||||
|
User user = null;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(query.UserId))
|
if (string.IsNullOrWhiteSpace(query.UserId))
|
||||||
{
|
{
|
||||||
inputItems = _libraryManager.RootFolder.GetRecursiveChildren(filter);
|
inputItems = _libraryManager.RootFolder.GetRecursiveChildren(filter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(query.UserId);
|
user = _userManager.GetUserById(query.UserId);
|
||||||
|
|
||||||
inputItems = user.RootFolder.GetRecursiveChildren(user, filter);
|
inputItems = user.RootFolder.GetRecursiveChildren(user, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputItems = _libraryManager.ReplaceVideosWithPrimaryVersions(inputItems);
|
inputItems = _libraryManager.ReplaceVideosWithPrimaryVersions(inputItems);
|
||||||
|
|
||||||
var results = await GetSearchHints(inputItems, query).ConfigureAwait(false);
|
var results = await GetSearchHints(inputItems, query, user).ConfigureAwait(false);
|
||||||
|
|
||||||
// Include item types
|
|
||||||
if (query.IncludeItemTypes.Length > 0)
|
|
||||||
{
|
|
||||||
results = results.Where(f => query.IncludeItemTypes.Contains(f.Item.GetType().Name, StringComparer.OrdinalIgnoreCase));
|
|
||||||
}
|
|
||||||
|
|
||||||
var searchResultArray = results.ToArray();
|
var searchResultArray = results.ToArray();
|
||||||
results = searchResultArray;
|
results = searchResultArray;
|
||||||
|
@ -86,9 +82,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inputItems">The input items.</param>
|
/// <param name="inputItems">The input items.</param>
|
||||||
/// <param name="query">The query.</param>
|
/// <param name="query">The query.</param>
|
||||||
|
/// <param name="user">The user.</param>
|
||||||
/// <returns>IEnumerable{SearchHintResult}.</returns>
|
/// <returns>IEnumerable{SearchHintResult}.</returns>
|
||||||
/// <exception cref="System.ArgumentNullException">searchTerm</exception>
|
/// <exception cref="System.ArgumentNullException">searchTerm</exception>
|
||||||
private Task<IEnumerable<SearchHintInfo>> GetSearchHints(IEnumerable<BaseItem> inputItems, SearchQuery query)
|
private Task<IEnumerable<SearchHintInfo>> GetSearchHints(IEnumerable<BaseItem> inputItems, SearchQuery query, User user)
|
||||||
{
|
{
|
||||||
var searchTerm = query.SearchTerm;
|
var searchTerm = query.SearchTerm;
|
||||||
|
|
||||||
|
@ -107,8 +104,25 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
|
|
||||||
if (query.IncludeMedia)
|
if (query.IncludeMedia)
|
||||||
{
|
{
|
||||||
|
var mediaItems = _libraryManager.GetItems(new InternalItemsQuery
|
||||||
|
{
|
||||||
|
NameContains = searchTerm,
|
||||||
|
ExcludeItemTypes = new[]
|
||||||
|
{
|
||||||
|
typeof (Person).Name,
|
||||||
|
typeof (Genre).Name,
|
||||||
|
typeof (MusicArtist).Name,
|
||||||
|
typeof (GameGenre).Name,
|
||||||
|
typeof (MusicGenre).Name,
|
||||||
|
typeof (Year).Name,
|
||||||
|
typeof (Studio).Name
|
||||||
|
},
|
||||||
|
IncludeItemTypes = query.IncludeItemTypes
|
||||||
|
|
||||||
|
}).Items;
|
||||||
|
|
||||||
// Add search hints based on item name
|
// Add search hints based on item name
|
||||||
hints.AddRange(items.Where(i => !string.IsNullOrWhiteSpace(i.Name) && IncludeInSearch(i)).Select(item =>
|
hints.AddRange(mediaItems.Where(i => (user == null || i.IsVisibleStandalone(user)) && !(i is CollectionFolder)).Select(item =>
|
||||||
{
|
{
|
||||||
var index = GetIndex(item.Name, searchTerm, terms);
|
var index = GetIndex(item.Name, searchTerm, terms);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
using MediaBrowser.Controller.Entities.TV;
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.LiveTv;
|
using MediaBrowser.Controller.LiveTv;
|
||||||
using MediaBrowser.Controller.Persistence;
|
using MediaBrowser.Controller.Persistence;
|
||||||
|
@ -867,7 +869,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
whereClauses.Add("type=@type");
|
whereClauses.Add("type=@type");
|
||||||
cmd.Parameters.Add(cmd, "@type", DbType.String).Value = includeTypes[0];
|
cmd.Parameters.Add(cmd, "@type", DbType.String).Value = includeTypes[0];
|
||||||
}
|
}
|
||||||
if (includeTypes.Length > 1)
|
else if (includeTypes.Length > 1)
|
||||||
{
|
{
|
||||||
var inClause = string.Join(",", includeTypes.Select(i => "'" + i + "'").ToArray());
|
var inClause = string.Join(",", includeTypes.Select(i => "'" + i + "'").ToArray());
|
||||||
whereClauses.Add(string.Format("type in ({0})", inClause));
|
whereClauses.Add(string.Format("type in ({0})", inClause));
|
||||||
|
@ -930,6 +932,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
cmd.Parameters.Add(cmd, "@PersonName", DbType.String).Value = query.Person;
|
cmd.Parameters.Add(cmd, "@PersonName", DbType.String).Value = query.Person;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(query.NameContains))
|
||||||
|
{
|
||||||
|
whereClauses.Add("Name like @NameContains");
|
||||||
|
cmd.Parameters.Add(cmd, "@NameContains", DbType.String).Value = "%" + query.NameContains + "%";
|
||||||
|
}
|
||||||
|
|
||||||
if (addPaging)
|
if (addPaging)
|
||||||
{
|
{
|
||||||
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
||||||
|
@ -947,17 +955,59 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
return whereClauses;
|
return whereClauses;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not crazy about having this all the way down here, but at least it's in one place
|
private static readonly Type[] KnownTypes =
|
||||||
readonly Dictionary<string, string[]> _types = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
|
|
||||||
{
|
{
|
||||||
{typeof(LiveTvProgram).Name, new []{typeof(LiveTvProgram).FullName}},
|
typeof(LiveTvProgram),
|
||||||
{typeof(LiveTvChannel).Name, new []{typeof(LiveTvChannel).FullName}},
|
typeof(LiveTvChannel),
|
||||||
{typeof(LiveTvVideoRecording).Name, new []{typeof(LiveTvVideoRecording).FullName}},
|
typeof(LiveTvVideoRecording),
|
||||||
{typeof(LiveTvAudioRecording).Name, new []{typeof(LiveTvAudioRecording).FullName}},
|
typeof(LiveTvAudioRecording),
|
||||||
{typeof(Series).Name, new []{typeof(Series).FullName}},
|
typeof(Series),
|
||||||
{"Recording", new []{typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName}}
|
typeof(LiveTvAudioRecording),
|
||||||
|
typeof(LiveTvVideoRecording),
|
||||||
|
typeof(Audio),
|
||||||
|
typeof(MusicAlbum),
|
||||||
|
typeof(MusicArtist),
|
||||||
|
typeof(MusicGenre),
|
||||||
|
typeof(MusicVideo),
|
||||||
|
typeof(Movie),
|
||||||
|
typeof(BoxSet),
|
||||||
|
typeof(Episode),
|
||||||
|
typeof(Season),
|
||||||
|
typeof(Series),
|
||||||
|
typeof(Book),
|
||||||
|
typeof(CollectionFolder),
|
||||||
|
typeof(Folder),
|
||||||
|
typeof(Game),
|
||||||
|
typeof(GameGenre),
|
||||||
|
typeof(GameSystem),
|
||||||
|
typeof(Genre),
|
||||||
|
typeof(Person),
|
||||||
|
typeof(Photo),
|
||||||
|
typeof(PhotoAlbum),
|
||||||
|
typeof(Studio),
|
||||||
|
typeof(UserRootFolder),
|
||||||
|
typeof(UserView),
|
||||||
|
typeof(Video),
|
||||||
|
typeof(Year)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static Dictionary<string, string[]> GetTypeMapDictionary()
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<string, string[]>();
|
||||||
|
|
||||||
|
foreach (var t in KnownTypes)
|
||||||
|
{
|
||||||
|
dict[t.Name] = new[] { t.FullName };
|
||||||
|
}
|
||||||
|
|
||||||
|
dict["Recording"] = new[] { typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName };
|
||||||
|
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not crazy about having this all the way down here, but at least it's in one place
|
||||||
|
readonly Dictionary<string, string[]> _types = GetTypeMapDictionary();
|
||||||
|
|
||||||
private IEnumerable<string> MapIncludeItemTypes(string value)
|
private IEnumerable<string> MapIncludeItemTypes(string value)
|
||||||
{
|
{
|
||||||
string[] result;
|
string[] result;
|
||||||
|
@ -1260,7 +1310,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
if (!string.IsNullOrWhiteSpace(query.NameContains))
|
if (!string.IsNullOrWhiteSpace(query.NameContains))
|
||||||
{
|
{
|
||||||
whereClauses.Add("Name like @NameContains");
|
whereClauses.Add("Name like @NameContains");
|
||||||
cmd.Parameters.Add(cmd, "@NameContains", DbType.String).Value = "%"+query.NameContains+"%";
|
cmd.Parameters.Add(cmd, "@NameContains", DbType.String).Value = "%" + query.NameContains + "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
return whereClauses;
|
return whereClauses;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user