protected static BrowseHit[] BuildHits(MyScoreDoc[] scoreDocs, SortField[] sortFields, IDictionary <string, IFacetHandler> facetHandlerMap, bool fetchStoredFields, IEnumerable <string> termVectorsToFetch, IFacetHandler groupBy, CombinedFacetAccessible[] groupAccessibles) { BrowseHit[] hits = new BrowseHit[scoreDocs.Length]; IEnumerable <IFacetHandler> facetHandlers = facetHandlerMap.Values; for (int i = scoreDocs.Length - 1; i >= 0; i--) { MyScoreDoc fdoc = scoreDocs[i]; BoboIndexReader reader = fdoc.reader; BrowseHit hit = new BrowseHit(); if (fetchStoredFields) { hit.StoredFields = reader.Document(fdoc.Doc); } if (termVectorsToFetch != null && termVectorsToFetch.Count() > 0) { var tvMap = new Dictionary <string, BrowseHit.TermFrequencyVector>(); hit.TermFreqMap = tvMap; foreach (string field in termVectorsToFetch) { ITermFreqVector tv = reader.GetTermFreqVector(fdoc.Doc, field); if (tv != null) { int[] freqs = tv.GetTermFrequencies(); string[] terms = tv.GetTerms(); tvMap[field] = new BrowseHit.TermFrequencyVector(terms, freqs); } } } var map = new Dictionary <string, string[]>(); var rawMap = new Dictionary <string, object[]>(); foreach (var facetHandler in facetHandlers) { map[facetHandler.Name] = facetHandler.GetFieldValues(reader, fdoc.Doc); rawMap[facetHandler.Name] = facetHandler.GetRawFieldValues(reader, fdoc.Doc); } hit.FieldValues = map; hit.RawFieldValues = rawMap; hit.DocId = fdoc.Doc + fdoc.queue.@base; hit.Score = fdoc.Score; hit.Comparable = fdoc.Value; if (groupBy != null) { hit.GroupField = groupBy.Name; hit.GroupValue = hit.GetField(groupBy.Name); hit.RawGroupValue = hit.GetRawField(groupBy.Name); if (groupAccessibles != null && hit.GroupValue != null && groupAccessibles != null && groupAccessibles.Length > 0) { BrowseFacet facet = groupAccessibles[0].GetFacet(hit.GroupValue); hit.GroupHitsCount = facet.FacetValueHitCount; } } hits[i] = hit; } return(hits); }
protected static BrowseHit[] BuildHits(MyScoreDoc[] scoreDocs, SortField[] sortFields, IDictionary <string, IFacetHandler> facetHandlerMap, bool fetchStoredFields, ICollection <string> termVectorsToFetch, IFacetHandler groupBy, CombinedFacetAccessible[] groupAccessibles) { BrowseHit[] hits = new BrowseHit[scoreDocs.Length]; IEnumerable <IFacetHandler> facetHandlers = facetHandlerMap.Values; for (int i = scoreDocs.Length - 1; i >= 0; i--) { MyScoreDoc fdoc = scoreDocs[i]; BoboSegmentReader reader = fdoc.m_reader; BrowseHit hit = new BrowseHit(); if (fetchStoredFields) { hit.SetStoredFields(reader.Document(fdoc.Doc)); } if (termVectorsToFetch != null && termVectorsToFetch.Count > 0) { var tvMap = new Dictionary <string, IList <BrowseHit.BoboTerm> >(); hit.TermVectorMap = tvMap; Fields fds = reader.GetTermVectors(fdoc.Doc); foreach (string field in termVectorsToFetch) { Terms terms = fds.GetTerms(field); if (terms == null) { continue; } TermsEnum termsEnum = terms.GetIterator(null); BytesRef text; DocsAndPositionsEnum docsAndPositions = null; List <BrowseHit.BoboTerm> boboTermList = new List <BrowseHit.BoboTerm>(); while ((text = termsEnum.Next()) != null) { BrowseHit.BoboTerm boboTerm = new BrowseHit.BoboTerm(); boboTerm.Term = text.Utf8ToString(); boboTerm.Freq = (int)termsEnum.TotalTermFreq; docsAndPositions = termsEnum.DocsAndPositions(null, docsAndPositions); if (docsAndPositions != null) { docsAndPositions.NextDoc(); boboTerm.Positions = new List <int>(); boboTerm.StartOffsets = new List <int>(); boboTerm.EndOffsets = new List <int>(); for (int t = 0; t < boboTerm.Freq; ++t) { boboTerm.Positions.Add(docsAndPositions.NextPosition()); boboTerm.StartOffsets.Add(docsAndPositions.StartOffset); boboTerm.EndOffsets.Add(docsAndPositions.EndOffset); } } boboTermList.Add(boboTerm); } tvMap.Put(field, boboTermList); } } var map = new Dictionary <string, string[]>(); var rawMap = new Dictionary <string, object[]>(); foreach (var facetHandler in facetHandlers) { map[facetHandler.Name] = facetHandler.GetFieldValues(reader, fdoc.Doc); rawMap[facetHandler.Name] = facetHandler.GetRawFieldValues(reader, fdoc.Doc); } hit.FieldValues = map; hit.RawFieldValues = rawMap; hit.DocId = fdoc.Doc + fdoc.m_queue.m_base; hit.Score = fdoc.Score; hit.Comparable = fdoc.Value; if (groupBy != null) { hit.GroupField = groupBy.Name; hit.GroupValue = hit.GetField(groupBy.Name); hit.RawGroupValue = hit.GetRawField(groupBy.Name); if (groupAccessibles != null && hit.GroupValue != null && groupAccessibles != null && groupAccessibles.Length > 0) { BrowseFacet facet = groupAccessibles[0].GetFacet(hit.GroupValue); hit.GroupHitsCount = facet.FacetValueHitCount; } } hits[i] = hit; } return(hits); }