internal ResultCollection(CrownPeakQueryResults <T> results, int start)
            : this()
        {
            Start      = start;
            TotalCount = results.NumFound;
            TimeTaken  = results.Header.QTime;
            CrownPeak  = results.CrownPeak;

            var dict    = new Dictionary <string, T>();
            int ordinal = start;

            foreach (var result in results)
            {
                result.Ordinal = ordinal++;
                if (results.Highlights != null)
                {
                    result.Highlights = new HighlightCollection(results.Highlights[result.Id]);
                }
                if (results.MaxScore.HasValue && results.MaxScore.Value > 0 && result.Score.HasValue)
                {
                    result.NormalizedScore = result.Score.Value / results.MaxScore.Value;
                }
                dict.Add(result.Id, result);
            }
            SetDictionary(dict);

            if (results.SpellChecking != null)
            {
                Suggestions = new SuggestionCollection(results.SpellChecking);
            }
            if (results.FacetFields != null)
            {
                Facets = new FacetCollection(results.FacetFields);
            }
        }
 private ResultCollection()
 {
     Start       = 0;
     TotalCount  = 0;
     TimeTaken   = 0;
     Suggestions = new SuggestionCollection();
     CrownPeak   = null;
 }
Exemplo n.º 3
0
        internal PlainResultCollection(CrownPeakQueryResults <Dictionary <string, object> > results, int start)
            : this()
        {
            Start      = start;
            TotalCount = results.NumFound;
            TimeTaken  = results.Header.QTime;
            CrownPeak  = results.CrownPeak;

            var dict = new Dictionary <string, PlainResult>();

            foreach (var result in results)
            {
                PlainResult r = new PlainResult(result);
                if (results.Highlights != null)
                {
                    r.SetHighlights(results.Highlights[r.Id]);
                }
                dict.Add(r.Id, r);
            }
            SetDictionary(dict);

            if (results.SpellChecking != null)
            {
                Suggestions = new SuggestionCollection(results.SpellChecking);
            }
            if (results.FacetFields != null)
            {
                Facets = new FacetCollection(results.FacetFields);
            }

            if (results.MaxScore.HasValue && results.MaxScore.Value > 0)
            {
                foreach (var result in results.Where(r => r.ContainsKey("score")))
                {
                    result.Add("normalizedScore", double.Parse(result["score"].ToString()) / results.MaxScore.Value);
                }
            }
        }