add people to similar queries

This commit is contained in:
Luke Pulverenti 2016-06-02 15:32:15 -04:00
parent ae168bc563
commit 05acd63f8f
2 changed files with 28 additions and 37 deletions

View File

@ -5,6 +5,8 @@ using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Server.Implementations.Persistence
@ -48,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
public static void BindGetSimilarityScore(IDbConnection connection, ILogger logger)
{
var sqlConnection = (SQLiteConnection) connection;
var sqlConnection = (SQLiteConnection)connection;
SimiliarToFunction.Logger = logger;
sqlConnection.BindFunction(new SimiliarToFunction());
}
@ -64,11 +66,23 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
[SQLiteFunction(Name = "GetSimilarityScore", Arguments = 12, FuncType = FunctionType.Scalar)]
[SQLiteFunction(Name = "GetSimilarityScore", Arguments = 13, FuncType = FunctionType.Scalar)]
public class SimiliarToFunction : SQLiteFunction
{
internal static ILogger Logger;
private readonly Dictionary<string, int> _personTypeScores = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
{
{ PersonType.Actor, 3},
{ PersonType.Director, 5},
{ PersonType.Composer, 2},
{ PersonType.GuestStar, 3},
{ PersonType.Writer, 2},
{ PersonType.Conductor, 2},
{ PersonType.Producer, 2},
{ PersonType.Lyricist, 2}
};
public override object Invoke(object[] args)
{
var score = 0;
@ -112,41 +126,14 @@ namespace MediaBrowser.Server.Implementations.Persistence
// studios
score += GetListScore(args, 10, 11, 3);
var rowPeopleNamesText = (args[12] as string) ?? string.Empty;
var rowPeopleNames = rowPeopleNamesText.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
// TODO: People
// var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id)
//.Select(i => i.Name)
//.Where(i => !string.IsNullOrWhiteSpace(i))
//.DistinctNames()
//.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
// points += item1People.Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i =>
// {
// if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase))
// {
// return 5;
// }
// if (string.Equals(i.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Actor, StringComparison.OrdinalIgnoreCase))
// {
// return 3;
// }
// if (string.Equals(i.Type, PersonType.Composer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Composer, StringComparison.OrdinalIgnoreCase))
// {
// return 3;
// }
// if (string.Equals(i.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))
// {
// return 3;
// }
// if (string.Equals(i.Type, PersonType.Writer, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase))
// {
// return 2;
// }
// return 1;
// });
// return points;
foreach (var name in rowPeopleNames)
{
// TODO: Send along person types
score += 3;
}
//Logger.Debug("Returning score {0}", score);
return score;

View File

@ -1638,7 +1638,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
builder.Append("(select group_concat((Select Value from ItemValues where ItemId=Guid and Type=5), '|')),");
builder.Append("@ItemStudios,");
builder.Append("Studios");
builder.Append("Studios,");
builder.Append("(select group_concat((Select Name from People where ItemId=Guid and Name in (Select Name from People where ItemId=@SimilarItemId)), '|'))");
builder.Append(") as SimilarityScore");
list.Add(builder.ToString());
@ -1648,6 +1651,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.Parameters.Add(cmd, "@ItemTags", DbType.String).Value = string.Join("|", item.Tags.ToArray());
cmd.Parameters.Add(cmd, "@ItemKeywords", DbType.String).Value = string.Join("|", item.Keywords.ToArray());
cmd.Parameters.Add(cmd, "@ItemStudios", DbType.String).Value = string.Join("|", item.Studios.ToArray());
cmd.Parameters.Add(cmd, "@SimilarItemId", DbType.Guid).Value = item.Id;
var excludeIds = query.ExcludeItemIds.ToList();
excludeIds.Add(item.Id.ToString("N"));