private int GetPopularity(Dictionary <ulong, uint> lookup, RankableSearchResultItem item)
        {
            uint count;

            lookup.TryGetValue(GetResultKey(item.Type, item.TypeId), out count);
            return(count.ToInt());
        }
        //--- Methods ---
        public RankableSearchResultItem Add(
            uint typeId,
            SearchResultType type,
            string title,
            double score,
            DateTime modified,
            double?rating,
            int ratingCount
            )
        {
            if (_ratingMidpoint == 0)
            {
                rating = rating ?? 0;
            }
            else if (rating.HasValue)
            {
                var r = rating.Value - _ratingMidpoint;
                rating = r > 0 ? r / (1 - _ratingMidpoint) : r / _ratingMidpoint;
            }
            var item = new RankableSearchResultItem(typeId, type, title, score, modified, rating ?? 0, ratingCount);
            var key  = item.DetailKey;

            if (_dedup.Contains(key))
            {
                _log.WarnFormat("Found duplicate entry for {0}:{1} in search results. The index is most likely corrupted and should be rebuilt", item.Type, item.TypeId);
                return(null);
            }
            _items.Add(item);
            _dedup.Add(key);
            return(item);
        }
        private double CalcRatingBoost(RankableSearchResultItem item) {

            // this does not try to do the capping that the real formula does. That is tested separately
            return _ratingPromotion * item.Rating / _ratingCount;
        }