Exemplo n.º 1
0
        public static CompatResult Append(this CompatResult remote, CompatResult local)
        {
            if (remote.Results?.Count > 0)
            {
                foreach (var localItem in local.Results)
                {
                    if (remote.Results.ContainsKey(localItem.Key))
                    {
                        continue;
                    }

                    remote.Results[localItem.Key] = localItem.Value;
                }
                return(remote);
            }
            return(local);
        }
        public static List <(string code, TitleInfo info, double score)> GetSortedList(this CompatResult result)
        {
            var search = result.RequestBuilder.search;

            if (string.IsNullOrEmpty(search) || !result.Results.Any())
            {
                return(result.Results
                       .OrderBy(kvp => kvp.Value.Title)
                       .ThenBy(kvp => kvp.Key)
                       .Select(kvp => (kvp.Key, kvp.Value, 0.0))
                       .ToList());
            }

            var sortedList = result.Results
                             .Select(kvp => (code: kvp.Key, info: kvp.Value, score: GetScore(search, kvp.Value)))
                             .OrderByDescending(t => t.score)
                             .ThenBy(t => t.info.Title)
                             .ThenBy(t => t.code)
                             .ToList();

            if (sortedList.First().score < 0.2)
            {
                sortedList = sortedList
                             .OrderBy(kvp => kvp.info.Title)
                             .ThenBy(kvp => kvp.code)
                             .ToList();
            }
            return(sortedList);
        }