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; }
/// <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); }
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); }
///<summary>browses the index.</summary> ///<param name="req">browse request </param> ///<returns> browse result </returns> public virtual BrowseResult Browse(BrowseRequest req) // throws BrowseException { if (reader == null) { return new BrowseResult(); } BrowseResult result = new BrowseResult(); long start = System.Environment.TickCount; int offset = req.Offset; int count = req.Count; if (offset < 0 || count <= 0) { throw new ArgumentException("the offset must be >= 0 and count must be > 0: " + offset + "/" + count); } TopDocsSortedHitCollector myHC = GetSortedHitCollector(req.Sort, offset, count, req.FetchStoredFields); Dictionary<string, IFacetAccessible> facetCollectors = new Dictionary<string, IFacetAccessible>(); Browse(req, myHC, facetCollectors); BrowseHit[] hits = null; try { hits = myHC.GetTopDocs(); } catch (System.IO.IOException e) { logger.Error(e.Message, e); hits = new BrowseHit[0]; } result.Hits = hits; result.NumHits = myHC.GetTotalHits(); result.TotalDocs = reader.NumDocs(); result.AddAll(facetCollectors); long end = System.Environment.TickCount; result.Time = end - start; return result; }