private static DocComparerSource GetComparerSource(IBrowsable browser, SortField sf) { DocComparerSource compSource = null; if (SortField.FIELD_DOC.Equals(sf)) { compSource = new DocComparerSource.DocIdDocComparerSource(); } else if (SortField.FIELD_SCORE.Equals(sf) || sf.Type == SortFieldType.SCORE) { // we want to do reverse sorting regardless for relevance compSource = new ReverseDocComparerSource(new DocComparerSource.RelevanceDocComparerSource()); } else if (sf is BoboCustomSortField) { BoboCustomSortField custField = (BoboCustomSortField)sf; DocComparerSource src = custField.GetCustomComparerSource(); Debug.Assert(src != null); compSource = src; } else { IEnumerable <string> facetNames = browser.FacetNames; string sortName = sf.Field; if (facetNames.Contains(sortName)) { var handler = browser.GetFacetHandler(sortName); Debug.Assert(handler != null); compSource = handler.GetDocComparerSource(); } else { // default lucene field logger.Info("doing default lucene sort for: " + sf); compSource = GetNonFacetComparerSource(sf); } } bool reverse = sf.IsReverse; if (reverse) { compSource = new ReverseDocComparerSource(compSource); } compSource.IsReverse = reverse; return(compSource); }
public static SortCollector BuildSortCollector(IBrowsable browser, Query q, SortField[] sort, int offset, int count, bool fetchStoredFields, ICollection <string> termVectorsToFetch, string[] groupBy, int maxPerGroup, bool collectDocIdCache) { if (sort == null || sort.Length == 0) { if (q != null && !(q is MatchAllDocsQuery)) { sort = new SortField[] { SortField.FIELD_SCORE }; } else { sort = new SortField[] { SortField.FIELD_DOC }; } } bool doScoring = false; foreach (SortField sf in sort) { if (sf.Type == SortFieldType.SCORE) { doScoring = true; break; } } DocComparerSource compSource; if (sort.Length == 1) { SortField sf = Convert(browser, sort[0]); compSource = GetComparerSource(browser, sf); } else { DocComparerSource[] compSources = new DocComparerSource[sort.Length]; for (int i = 0; i < sort.Length; ++i) { compSources[i] = GetComparerSource(browser, Convert(browser, sort[i])); } compSource = new MultiDocIdComparerSource(compSources); } return(new SortCollectorImpl(compSource, sort, browser, offset, count, doScoring, fetchStoredFields, termVectorsToFetch, groupBy, maxPerGroup, collectDocIdCache)); }
public SortCollectorImpl( DocComparerSource compSource, SortField[] sortFields, IBrowsable boboBrowser, int offset, int count, bool doScoring, bool fetchStoredFields, ICollection <string> termVectorsToFetch, string[] groupBy, int maxPerGroup, bool collectDocIdCache) : base(sortFields, fetchStoredFields) { Debug.Assert(offset >= 0 && count >= 0); m_boboBrowser = boboBrowser; m_compSource = compSource; m_pqList = new List <DocIDPriorityQueue>(); m_numHits = offset + count; m_offset = offset; m_count = count; m_totalHits = 0; m_queueFull = false; m_doScoring = doScoring; m_tmpScoreDoc = new MyScoreDoc(); m_termVectorsToFetch = termVectorsToFetch; // NightOwl888: The _collectDocIdCache setting seems to put arrays into // memory, but then do nothing with the arrays. Seems wasteful and unnecessary. //_collectDocIdCache = collectDocIdCache || groupBy != null; if (groupBy != null && groupBy.Length != 0) { var groupByList = new List <IFacetHandler>(groupBy.Length); foreach (string field in groupBy) { IFacetHandler handler = boboBrowser.GetFacetHandler(field); if (handler != null) { groupByList.Add(handler); } } if (groupByList.Count > 0) { this.m_groupByMulti = groupByList.ToArray(); this.m_groupBy = m_groupByMulti[0]; } if (this.m_groupBy != null && m_count > 0) { if (m_groupByMulti.Length == 1) { //_currentValueDocMaps = new Int2ObjectOpenHashMap<ScoreDoc>(_count); m_currentValueDocMaps = new Dictionary <int, ScoreDoc>(m_count); m_facetAccessibleLists = null; } else { m_currentValueDocMaps = null; m_facetCountCollectorMulti = new IFacetCountCollector[groupByList.Count - 1]; m_facetAccessibleLists = new List <IFacetAccessible> [m_facetCountCollectorMulti.Length]; for (int i = 0; i < m_facetCountCollectorMulti.Length; ++i) { m_facetAccessibleLists[i] = new List <IFacetAccessible>(); } } // NightOwl888: The _collectDocIdCache setting seems to put arrays into // memory, but then do nothing with the arrays. Seems wasteful and unnecessary. //if (_collectDocIdCache) //{ // contextList = new List<CollectorContext>(); // docidarraylist = new List<int[]>(); // if (doScoring) // scorearraylist = new List<float[]>(); //} } else { m_currentValueDocMaps = null; m_facetAccessibleLists = null; } } else { m_currentValueDocMaps = null; m_facetAccessibleLists = null; } }
public ReverseDocComparerSource(DocComparerSource inner) { m_inner = inner; }