Пример #1
0
        private IList <EntityInfo> ExtractEntityInfos(IndexSearcher searcher)
        {
            TopDocs hits = GetTopDocs(searcher);

            SetResultSize(hits);
            int first = First();
            int max   = Max(first, hits);
            int size  = Math.Max(0, max - first + 1);
            IList <EntityInfo> infos = new List <EntityInfo>(size);

            if (size <= 0)
            {
                return(infos);
            }

            DocumentExtractor extractor = new DocumentExtractor(SearchFactory, indexProjection);

            for (int index = first; index <= max; index++)
            {
                //TODO use indexSearcher.getIndexReader().document( hits.id(index), FieldSelector(indexProjection) );
                infos.Add(extractor.Extract(hits, searcher, index));
            }

            return(infos);
        }
Пример #2
0
        /// <summary>
        /// Return an interator on the results.
        /// Retrieve the object one by one (initialize it during the next() operation)
        /// </summary>
        public override IEnumerable <T> Enumerable <T>()
        {
            using (new SessionIdLoggingContext(Session.SessionId))
            {
                //implement an interator which keep the id/class for each hit and get the object on demand
                //cause I can't keep the searcher and hence the hit opened. I dont have any hook to know when the
                //user stop using it
                //scrollable is better in this area

                //find the directories
                IndexSearcher searcher = BuildSearcher();
                if (searcher == null)
                {
                    return(new IteratorImpl <T>(new List <EntityInfo>(), noLoader).Iterate());
                }

                try
                {
                    var topDocs = GetTopDocs(searcher);
                    SetResultSize(topDocs);
                    int first = First();
                    int max   = Max(first, topDocs);

                    int size = max - first + 1 < 0 ? 0 : max - first + 1;
                    IList <EntityInfo> infos     = new List <EntityInfo>(size);
                    DocumentExtractor  extractor = new DocumentExtractor(SearchFactory, indexProjection);
                    for (int index = first; index <= max; index++)
                    {
                        //TODO use indexSearcher.getIndexReader().document( hits.id(index), FieldSelector(indexProjection) );
                        infos.Add(extractor.Extract(topDocs, searcher, index));
                    }
                    return(new IteratorImpl <T>(infos, this.GetLoader((ISession)Session)).Iterate());
                }
                catch (IOException e)
                {
                    throw new HibernateException("Unable to query Lucene index", e);
                }
                finally
                {
                    CloseSearcher(searcher);
                }
            }
        }