예제 #1
0
        public override FullSearchResult GetResult(string url)
        {
            FullSearchResult r;
            //var r = base.GetResult(url);

            var tm = GetApiResults(url, out var code, out var res, out var msg);

            if (tm?.docs != null)
            {
                // Most similar to least similar

                try
                {
                    var results = ConvertResults(tm).ToList();
                    var best    = results[0];

                    r = new FullSearchResult(this, best.Url, best.Similarity)
                    {
                        Source      = best.Source,
                        Description = best.Description,
                    };
                    r.Filter = r.Similarity < FilterThreshold;

                    r.AddExtendedResults(results);
                }
                catch (Exception e)
                {
                    r = base.GetResult(url);
                    r.AddErrorMessage(e.Message);
                    return(r);
                }
            }
            else
            {
                r = base.GetResult(url);

                r.AddErrorMessage(msg);
            }


            return(r);
        }
예제 #2
0
        public override FullSearchResult GetResult(string url)
        {
            FullSearchResult result = base.GetResult(url);

            try
            {
                var orig = GetDataResults(url);

                if (orig == null)
                {
                    //return result;
                    Debug.WriteLine("Parsing HTML from SN!");
                    orig = ParseResults(url).ToArray();
                }

                // aggregate all info for primary result

                string?character = orig.FirstOrDefault(o => !String.IsNullOrWhiteSpace(o.Character))?.Character;
                string?creator   = orig.FirstOrDefault(o => !String.IsNullOrWhiteSpace(o.Creator))?.Creator;
                string?material  = orig.FirstOrDefault(o => !String.IsNullOrWhiteSpace(o.Material))?.Material;


                var extended = ConvertDataResults(orig).ToList();

                var ordered = extended
                              .Where(e => e.Url != null)
                              .OrderByDescending(e => e.Similarity)
                              .ToList();


                if (!ordered.Any())
                {
                    // No good results

                    result.Filter = true;
                    return(result);
                }

                var best = ordered.First();


                // Copy
                result.UpdateFrom(best);

                result.Characters = character;
                result.Artist     = creator;
                result.Source     = material;

                result.AddExtendedResults(extended);

                if (!String.IsNullOrWhiteSpace(m_apiKey))
                {
                    result.Metadata.Add("API", "Enabled");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"SauceNao error: {e.StackTrace}");
                result.AddErrorMessage(e.Message);
            }

            return(result);
        }