示例#1
0
        public IEnumerable <IMultiGetHit <T> > GetMany <T>(IEnumerable <string> ids) where T : class
        {
            var docs = Hits.OfType <IMultiGetHit <T> >();

            return(from d in docs
                   join id in ids on d.Id equals id
                   select d);
        }
        /// <summary>
        /// Retrieves the hits for each distinct id.
        /// </summary>
        /// <param name="ids">The ids to retrieve source for</param>
        /// <typeparam name="T">The document type for the hits to return</typeparam>
        /// <returns>An IEnumerable{T} of hits</returns>
        public IEnumerable <IMultiGetHit <T> > GetMany <T>(IEnumerable <string> ids) where T : class
        {
            HashSet <string> seenIndices = null;

            foreach (var id in ids.Distinct())
            {
                if (seenIndices == null)
                {
                    seenIndices = new HashSet <string>();
                }
                else
                {
                    seenIndices.Clear();
                }

                foreach (var doc in Hits.OfType <IMultiGetHit <T> >())
                {
                    if (string.Equals(doc.Id, id) && seenIndices.Add(doc.Index))
                    {
                        yield return(doc);
                    }
                }
            }
        }
 public MultiGetHit <T> Get <T>(string id) where T : class => Hits.OfType <MultiGetHit <T> >().FirstOrDefault(m => m.Id == id);