update search

This commit is contained in:
Luke Pulverenti 2015-08-21 22:59:10 -04:00
parent 4307c67b5e
commit de133cb8aa
13 changed files with 230 additions and 228 deletions

View File

@ -485,6 +485,7 @@ namespace MediaBrowser.Controller.Entities
/// Gets or sets the parent.
/// </summary>
/// <value>The parent.</value>
[IgnoreDataMember]
public Folder Parent
{
get

View File

@ -30,6 +30,12 @@ namespace MediaBrowser.Controller.LiveTv
return GetClientTypeName() + "-" + Name;
}
/// <summary>
/// Gets or sets the etag.
/// </summary>
/// <value>The etag.</value>
public string Etag { get; set; }
/// <summary>
/// Id of the program.
/// </summary>

View File

@ -180,6 +180,11 @@ namespace MediaBrowser.Controller.LiveTv
/// </summary>
/// <value>The episode number.</value>
public int? EpisodeNumber { get; set; }
/// <summary>
/// Gets or sets the etag.
/// </summary>
/// <value>The etag.</value>
public string Etag { get; set; }
public ProgramInfo()
{

View File

@ -33,26 +33,17 @@ namespace MediaBrowser.Server.Implementations.Library
public async Task<QueryResult<SearchHintInfo>> GetSearchHints(SearchQuery query)
{
IEnumerable<BaseItem> inputItems;
Func<BaseItem, bool> filter = i => !(i is ICollectionFolder);
User user = null;
if (string.IsNullOrWhiteSpace(query.UserId))
{
inputItems = _libraryManager.RootFolder.GetRecursiveChildren(filter);
}
else
{
user = _userManager.GetUserById(query.UserId);
inputItems = user.RootFolder.GetRecursiveChildren(user, filter);
}
inputItems = _libraryManager.ReplaceVideosWithPrimaryVersions(inputItems);
var results = await GetSearchHints(inputItems, query, user).ConfigureAwait(false);
var results = await GetSearchHints(query, user).ConfigureAwait(false);
var searchResultArray = results.ToArray();
results = searchResultArray;
@ -77,15 +68,22 @@ namespace MediaBrowser.Server.Implementations.Library
};
}
private void AddIfMissing(List<string> list, string value)
{
if (!list.Contains(value, StringComparer.OrdinalIgnoreCase))
{
list.Add(value);
}
}
/// <summary>
/// Gets the search hints.
/// </summary>
/// <param name="inputItems">The input items.</param>
/// <param name="query">The query.</param>
/// <param name="user">The user.</param>
/// <returns>IEnumerable{SearchHintResult}.</returns>
/// <exception cref="System.ArgumentNullException">searchTerm</exception>
private Task<IEnumerable<SearchHintInfo>> GetSearchHints(IEnumerable<BaseItem> inputItems, SearchQuery query, User user)
private Task<IEnumerable<SearchHintInfo>> GetSearchHints(SearchQuery query, User user)
{
var searchTerm = query.SearchTerm;
@ -100,207 +98,80 @@ namespace MediaBrowser.Server.Implementations.Library
var hints = new List<Tuple<BaseItem, string, int>>();
var items = inputItems.Where(i => !(i is MusicArtist)).ToList();
var excludeItemTypes = new List<string>();
var includeItemTypes = (query.IncludeItemTypes ?? new string[] { }).ToList();
if (query.IncludeMedia)
excludeItemTypes.Add(typeof(Year).Name);
if (query.IncludeGenres && (includeItemTypes.Count == 0 || includeItemTypes.Contains("Genre", StringComparer.OrdinalIgnoreCase)))
{
var mediaItems = _libraryManager.GetItems(new InternalItemsQuery
if (!query.IncludeMedia)
{
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
hints.AddRange(mediaItems.Where(i => IncludeInSearch(i) && (user == null || i.IsVisibleStandalone(user)) && !(i is CollectionFolder)).Select(item =>
{
var index = GetIndex(item.Name, searchTerm, terms);
return new Tuple<BaseItem, string, int>(item, index.Item1, index.Item2);
}));
}
if (query.IncludeArtists && (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains("MusicArtist", StringComparer.OrdinalIgnoreCase)))
{
// Find artists
var artists = items.OfType<Audio>()
.SelectMany(i => i.AllArtists)
.Where(i => !string.IsNullOrWhiteSpace(i))
.DistinctNames()
.ToList();
foreach (var item in artists)
{
var index = GetIndex(item, searchTerm, terms);
if (index.Item2 != -1)
{
try
{
var artist = _libraryManager.GetArtist(item);
hints.Add(new Tuple<BaseItem, string, int>(artist, index.Item1, index.Item2));
}
catch (Exception ex)
{
_logger.ErrorException("Error getting {0}", ex, item);
}
}
AddIfMissing(includeItemTypes, typeof(Genre).Name);
AddIfMissing(includeItemTypes, typeof(GameGenre).Name);
AddIfMissing(includeItemTypes, typeof(MusicGenre).Name);
}
}
if (query.IncludeGenres && (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains("Genre", StringComparer.OrdinalIgnoreCase)))
else
{
// Find genres, from non-audio items
var genres = items.Where(i => !(i is IHasMusicGenres) && !(i is Game))
.SelectMany(i => i.Genres)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
foreach (var item in genres)
{
var index = GetIndex(item, searchTerm, terms);
if (index.Item2 != -1)
{
try
{
var genre = _libraryManager.GetGenre(item);
hints.Add(new Tuple<BaseItem, string, int>(genre, index.Item1, index.Item2));
}
catch (Exception ex)
{
_logger.ErrorException("Error getting {0}", ex, item);
}
}
}
// Find music genres
var musicGenres = items.Where(i => i is IHasMusicGenres)
.SelectMany(i => i.Genres)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
foreach (var item in musicGenres)
{
var index = GetIndex(item, searchTerm, terms);
if (index.Item2 != -1)
{
try
{
var genre = _libraryManager.GetMusicGenre(item);
hints.Add(new Tuple<BaseItem, string, int>(genre, index.Item1, index.Item2));
}
catch (Exception ex)
{
_logger.ErrorException("Error getting {0}", ex, item);
}
}
}
// Find music genres
var gameGenres = items.OfType<Game>()
.SelectMany(i => i.Genres)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
foreach (var item in gameGenres)
{
var index = GetIndex(item, searchTerm, terms);
if (index.Item2 != -1)
{
try
{
var genre = _libraryManager.GetGameGenre(item);
hints.Add(new Tuple<BaseItem, string, int>(genre, index.Item1, index.Item2));
}
catch (Exception ex)
{
_logger.ErrorException("Error getting {0}", ex, item);
}
}
}
AddIfMissing(excludeItemTypes, typeof(Genre).Name);
AddIfMissing(excludeItemTypes, typeof(GameGenre).Name);
AddIfMissing(excludeItemTypes, typeof(MusicGenre).Name);
}
if (query.IncludeStudios && (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains("Studio", StringComparer.OrdinalIgnoreCase)))
if (query.IncludePeople && (includeItemTypes.Count == 0 || includeItemTypes.Contains("People", StringComparer.OrdinalIgnoreCase)))
{
// Find studios
var studios = items.SelectMany(i => i.Studios)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
foreach (var item in studios)
if (!query.IncludeMedia)
{
var index = GetIndex(item, searchTerm, terms);
if (index.Item2 != -1)
{
try
{
var studio = _libraryManager.GetStudio(item);
hints.Add(new Tuple<BaseItem, string, int>(studio, index.Item1, index.Item2));
}
catch (Exception ex)
{
_logger.ErrorException("Error getting {0}", ex, item);
}
}
AddIfMissing(includeItemTypes, typeof(Person).Name);
}
}
if (query.IncludePeople && (query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains("Person", StringComparer.OrdinalIgnoreCase)))
else
{
var itemIds = items.Select(i => i.Id).ToList();
AddIfMissing(excludeItemTypes, typeof(Person).Name);
}
// Find persons
var persons = _libraryManager.GetPeople(new InternalPeopleQuery
if (query.IncludeStudios && (includeItemTypes.Count == 0 || includeItemTypes.Contains("Studio", StringComparer.OrdinalIgnoreCase)))
{
if (!query.IncludeMedia)
{
NameContains = searchTerm
})
.Where(i => itemIds.Contains(i.ItemId))
.Select(i => i.Name)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
foreach (var item in persons)
{
var index = GetIndex(item, searchTerm, terms);
if (index.Item2 != -1)
{
try
{
var person = _libraryManager.GetPerson(item);
hints.Add(new Tuple<BaseItem, string, int>(person, index.Item1, index.Item2));
}
catch (Exception ex)
{
_logger.ErrorException("Error getting {0}", ex, item);
}
}
AddIfMissing(includeItemTypes, typeof(Studio).Name);
}
}
else
{
AddIfMissing(excludeItemTypes, typeof(Studio).Name);
}
if (query.IncludeArtists && (includeItemTypes.Count == 0 || includeItemTypes.Contains("MusicArtist", StringComparer.OrdinalIgnoreCase)))
{
if (!query.IncludeMedia)
{
AddIfMissing(includeItemTypes, typeof(MusicArtist).Name);
}
}
else
{
AddIfMissing(excludeItemTypes, typeof(MusicArtist).Name);
}
var mediaItems = _libraryManager.GetItems(new InternalItemsQuery
{
NameContains = searchTerm,
ExcludeItemTypes = excludeItemTypes.ToArray(),
IncludeItemTypes = includeItemTypes.ToArray(),
MaxParentalRating = user == null ? null : user.Policy.MaxParentalRating,
Limit = query.Limit.HasValue ? query.Limit * 3 : null
}).Items;
// Add search hints based on item name
hints.AddRange(mediaItems.Where(i => IncludeInSearch(i) && IsVisible(i, user) && !(i is CollectionFolder)).Select(item =>
{
var index = GetIndex(item.Name, searchTerm, terms);
return new Tuple<BaseItem, string, int>(item, index.Item1, index.Item2);
}));
var returnValue = hints.Where(i => i.Item3 >= 0).OrderBy(i => i.Item3).Select(i => new SearchHintInfo
{
@ -311,13 +182,32 @@ namespace MediaBrowser.Server.Implementations.Library
return Task.FromResult(returnValue);
}
private bool IsVisible(BaseItem item, User user)
{
if (user == null)
{
return true;
}
if (item is IItemByName)
{
var dual = item as IHasDualAccess;
if (dual == null || dual.IsAccessedByName)
{
return true;
}
}
return item.IsVisibleStandalone(user);
}
private bool IncludeInSearch(BaseItem item)
{
var episode = item as Episode;
if (episode != null)
{
if (episode.IsVirtualUnaired || episode.IsMissingEpisode)
if (episode.IsMissingEpisode)
{
return false;
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities;
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
@ -42,12 +43,16 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
var numComplete = 0;
var count = items.Count;
var validIds = new List<Guid>();
foreach (var name in items)
{
try
{
var itemByName = _libraryManager.GetGameGenre(name);
validIds.Add(itemByName.Id);
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
@ -68,6 +73,26 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
progress.Report(percent);
}
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(GameGenre).Name }
});
var invalidIds = allIds
.Except(validIds)
.ToList();
foreach (var id in invalidIds)
{
var item = _libraryManager.GetItemById(id);
await _libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false
}).ConfigureAwait(false);
}
progress.Report(100);
}
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities;
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
@ -43,12 +44,16 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
var numComplete = 0;
var count = items.Count;
var validIds = new List<Guid>();
foreach (var name in items)
{
try
{
var itemByName = _libraryManager.GetGenre(name);
validIds.Add(itemByName.Id);
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
@ -69,6 +74,26 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
progress.Report(percent);
}
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Genre).Name }
});
var invalidIds = allIds
.Except(validIds)
.ToList();
foreach (var id in invalidIds)
{
var item = _libraryManager.GetItemById(id);
await _libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false
}).ConfigureAwait(false);
}
progress.Report(100);
}
}

View File

@ -1,4 +1,6 @@
using MediaBrowser.Controller.Entities.Audio;
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
@ -42,12 +44,16 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
var numComplete = 0;
var count = items.Count;
var validIds = new List<Guid>();
foreach (var name in items)
{
try
{
var itemByName = _libraryManager.GetMusicGenre(name);
validIds.Add(itemByName.Id);
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
@ -68,6 +74,26 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
progress.Report(percent);
}
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(MusicGenre).Name }
});
var invalidIds = allIds
.Except(validIds)
.ToList();
foreach (var id in invalidIds)
{
var item = _libraryManager.GetItemById(id);
await _libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false
}).ConfigureAwait(false);
}
progress.Report(100);
}
}

View File

@ -1,6 +1,8 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -41,12 +43,16 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
var numComplete = 0;
var count = items.Count;
var validIds = new List<Guid>();
foreach (var name in items)
{
try
{
var itemByName = _libraryManager.GetStudio(name);
validIds.Add(itemByName.Id);
await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
@ -67,6 +73,26 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
progress.Report(percent);
}
var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Studio).Name }
});
var invalidIds = allIds
.Except(validIds)
.ToList();
foreach (var id in invalidIds)
{
var item = _libraryManager.GetItemById(id);
await _libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false
}).ConfigureAwait(false);
}
progress.Report(100);
}
}

View File

@ -627,31 +627,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
private async Task UpdateTimersForSeriesTimer(List<ProgramInfo> epgData, SeriesTimerInfo seriesTimer)
{
var newTimers = GetTimersForSeries(seriesTimer, epgData, _recordingProvider.GetAll()).ToList();
var existingTimers = _timerProvider.GetAll()
.Where(i => string.Equals(i.SeriesTimerId, seriesTimer.Id, StringComparison.OrdinalIgnoreCase))
.ToList();
var registration = await GetRegistrationInfo("seriesrecordings").ConfigureAwait(false);
if (registration.IsValid)
{
var newTimers = GetTimersForSeries(seriesTimer, epgData, _recordingProvider.GetAll()).ToList();
foreach (var timer in newTimers)
{
_timerProvider.AddOrUpdate(timer);
}
}
var newTimerIds = newTimers.Select(i => i.Id).ToList();
foreach (var timer in existingTimers)
{
if (!newTimerIds.Contains(timer.Id, StringComparer.OrdinalIgnoreCase))
{
CancelTimerInternal(timer.Id);
}
}
}
private IEnumerable<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer, IEnumerable<ProgramInfo> allPrograms, IReadOnlyList<RecordingInfo> currentRecordings)

View File

@ -304,7 +304,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
IsKids = string.Equals(details.audience, "children", StringComparison.OrdinalIgnoreCase),
IsSports = showType.IndexOf("sports", StringComparison.OrdinalIgnoreCase) != -1,
IsMovie = showType.IndexOf("movie", StringComparison.OrdinalIgnoreCase) != -1 || showType.IndexOf("film", StringComparison.OrdinalIgnoreCase) != -1,
ShowId = programInfo.programID
ShowId = programInfo.programID,
Etag = programInfo.md5
};
if (programInfo.videoProperties != null)
@ -408,7 +409,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
;
});
imageIdString = imageIdString.TrimEnd(',') + "]";
_logger.Debug("Json for show images = " + imageIdString);
var httpOptions = new HttpRequestOptions()
{
Url = ApiUrl + "/metadata/programs",

View File

@ -593,7 +593,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
Name = info.Name,
Id = id,
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow
DateModified = DateTime.UtcNow,
Etag = info.Etag
};
}
@ -639,7 +640,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}
else
{
await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(info.Etag) || !string.Equals(info.Etag, item.Etag, StringComparison.OrdinalIgnoreCase))
{
item.Etag = info.Etag;
await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
}
}
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions());

View File

@ -61,7 +61,7 @@ namespace MediaBrowser.WebDashboard.Api
// jQuery ajax doesn't seem to handle if-modified-since correctly
if (IsFormat(path, "html"))
{
if (IsCoreHtml(path))
if (IsCoreHtml(path) && path.IndexOf(".template.html", StringComparison.OrdinalIgnoreCase) == -1)
{
resourceStream = await ModifyHtml(resourceStream, mode, appVersion, localizationCulture, enableMinification).ConfigureAwait(false);
}

View File

@ -186,9 +186,6 @@
<Content Include="dashboard-ui\css\nowplayingbar.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\livetvguideprovider-scd.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\livetvguideprovider.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -222,9 +219,6 @@
<Content Include="dashboard-ui\scripts\homeupcoming.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\livetvguideprovider-scd.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\livetvguideprovider.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -264,6 +258,9 @@
<Content Include="dashboard-ui\scripts\slideshow.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\wizardlivetvguide.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\wizardlivetvtuner.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -377,6 +374,12 @@
<Content Include="dashboard-ui\thirdparty\viblast\worker.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\tvproviders\schedulesdirect.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\tvproviders\schedulesdirect.template.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\voice\voice.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -1786,6 +1789,9 @@
<Content Include="dashboard-ui\wizardagreement.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\wizardlivetvguide.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\wizardlivetvtuner.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>