Example #1
0
 public virtual SortCollector GetSortCollector(
     SortField[] sort,
     Lucene.Net.Search.Query q,
     int offset,
     int count,
     bool fetchStoredFields,
     IEnumerable <string> termVectorsToFetch,
     bool forceScoring,
     string[] groupBy,
     int maxPerGroup,
     bool collectDocIdCache)
 {
     return(SortCollector.BuildSortCollector(
                this,
                q,
                sort,
                offset,
                count,
                forceScoring,
                fetchStoredFields,
                termVectorsToFetch,
                groupBy,
                maxPerGroup,
                collectDocIdCache));
 }
Example #2
0
 public virtual SortCollector GetSortCollector(SortField[] sort, Lucene.Net.Search.Query q, int offset, int count,
                                               bool fetchStoredFields, ICollection <string> termVectorsToFetch, string[] groupBy, int maxPerGroup,
                                               bool collectDocIdCache)
 {
     if (m_subBrowsers.Length == 1)
     {
         return(m_subBrowsers[0].GetSortCollector(sort, q, offset, count, fetchStoredFields,
                                                  termVectorsToFetch, groupBy, maxPerGroup, collectDocIdCache));
     }
     return(SortCollector.BuildSortCollector(this, q, sort, offset, count, fetchStoredFields,
                                             termVectorsToFetch, groupBy, maxPerGroup, collectDocIdCache));
 }
Example #3
0
        public virtual BrowseResult Browse(BrowseRequest req)
        {
            if (_reader == null)
            {
                return(new BrowseResult());
            }

            BrowseResult result = new BrowseResult();

            long start = System.Environment.TickCount;

            SortCollector collector = GetSortCollector(req.Sort, req.Query, req.Offset, req.Count, req.FetchStoredFields, req.TermVectorsToFetch, false, req.GroupBy, req.MaxPerGroup, req.CollectDocIdCache);

            IDictionary <string, IFacetAccessible> facetCollectors = new Dictionary <string, IFacetAccessible>();

            Browse(req, collector, facetCollectors);
            BrowseHit[] hits = null;

            try
            {
                hits = collector.TopDocs;
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                hits = new BrowseHit[0];
            }

            var q = req.Query;

            if (q == null)
            {
                q = new MatchAllDocsQuery();
            }
            if (req.ShowExplanation)
            {
                foreach (BrowseHit hit in hits)
                {
                    try
                    {
                        Explanation expl = Explain(q, hit.DocId);
                        hit.Explanation = expl;
                    }
                    catch (Exception e)
                    {
                        logger.Error(e.Message, e);
                    }
                }
            }
            result.Hits             = hits;
            result.NumHits          = collector.TotalHits;
            result.NumGroups        = collector.TotalGroups;
            result.GroupAccessibles = collector.GroupAccessibles;
            result.SortCollector    = collector;
            result.TotalDocs        = _reader.NumDocs();
            result.AddAll(facetCollectors);
            long end = System.Environment.TickCount;

            result.Time = (end - start);
            return(result);
        }
Example #4
0
        /// <summary>
        /// Generates a merged BrowseResult from the supplied <see cref="T:BrowseRequest"/>.
        /// </summary>
        /// <param name="req"><see cref="T:BrowseRequest"/> for generating the facets.</param>
        /// <returns><see cref="T:BrowseResult"/> of the results corresponding to the <see cref="T:BrowseRequest"/>.</returns>
        public virtual BrowseResult Browse(BrowseRequest req)
        {
            BrowseResult result = new BrowseResult();

            // index empty
            if (m_subBrowsers == null || m_subBrowsers.Length == 0)
            {
                return(result);
            }
            long start  = System.Environment.TickCount;
            int  offset = req.Offset;
            int  count  = req.Count;

            if (offset < 0 || count < 0)
            {
                throw new ArgumentOutOfRangeException("both offset and count must be > 0: " + offset + "/" + count);
            }
            SortCollector collector = GetSortCollector(req.Sort, req.Query, offset, count,
                                                       req.FetchStoredFields, req.TermVectorsToFetch, req.GroupBy, req.MaxPerGroup,
#pragma warning disable 612, 618
                                                       req.CollectDocIdCache);

#pragma warning restore 612, 618

            var facetCollectors = new Dictionary <string, IFacetAccessible>();
            Browse(req, collector, facetCollectors, 0);

            if (req.MapReduceWrapper != null)
            {
                result.MapReduceResult = req.MapReduceWrapper.Result;
            }
            BrowseHit[] hits = null;
            try
            {
                hits = collector.TopDocs;
            }
            catch (Exception e)
            {
                logger.ErrorException(e.Message, e);
                result.AddError(e.Message);
                hits = new BrowseHit[0];
            }

            var q = req.Query;
            if (req.ShowExplanation)
            {
                foreach (BrowseHit hit in hits)
                {
                    try
                    {
                        int         doc        = hit.DocId;
                        int         idx        = ReaderIndex(doc);
                        int         deBasedDoc = doc - ReaderBase(idx);
                        Explanation expl       = m_subBrowsers[idx].Explain(q, deBasedDoc);
                        hit.SetExplanation(expl);
                    }
                    catch (Exception e)
                    {
                        logger.ErrorException(e.Message, e);
                        result.AddError(e.Message);
                    }
                }
            }

            result.Hits             = hits;
            result.NumHits          = collector.TotalHits;
            result.NumGroups        = collector.TotalGroups;
            result.GroupAccessibles = collector.GroupAccessibles;
            result.SortCollector    = collector;
            result.TotalDocs        = this.NumDocs;
            result.AddAll(facetCollectors);
            long end = System.Environment.TickCount;
            result.Time = (end - start);
            // set the transaction ID to trace transactions
            result.Tid = req.Tid;
            return(result);
        }