コード例 #1
0
        public static SortCollector BuildSortCollector(IBrowsable browser, Query q, SortField[] sort,
                                                       int offset, int count, bool forceScoring, bool fetchStoredFields, IEnumerable <string> termVectorsToFetch,
                                                       string[] groupBy, int maxPerGroup, bool collectDocIdCache)
        {
            bool doScoring = forceScoring;

            if (sort == null || sort.Length == 0)
            {
                if (q != null && !(q is MatchAllDocsQuery))
                {
                    sort = new SortField[] { SortField.FIELD_SCORE };
                }
            }

            if (sort == null || sort.Length == 0)
            {
                sort = new SortField[] { SortField.FIELD_DOC };
            }

            IEnumerable <string> facetNames = browser.FacetNames;

            foreach (SortField sf in sort)
            {
                if (sf.Type == SortField.SCORE)
                {
                    doScoring = true;
                    break;
                }
            }

            DocComparatorSource compSource;

            if (sort.Length == 1)
            {
                SortField sf = Convert(browser, sort[0]);
                compSource = GetComparatorSource(browser, sf);
            }
            else
            {
                DocComparatorSource[] compSources = new DocComparatorSource[sort.Length];
                for (int i = 0; i < sort.Length; ++i)
                {
                    compSources[i] = GetComparatorSource(browser, Convert(browser, sort[i]));
                }
                compSource = new MultiDocIdComparatorSource(compSources);
            }
            return(new SortCollectorImpl(compSource, sort, browser, offset, count, doScoring, fetchStoredFields, termVectorsToFetch, groupBy, maxPerGroup, collectDocIdCache));
        }
コード例 #2
0
        private static DocComparatorSource GetComparatorSource(IBrowsable browser, SortField sf)
        {
            DocComparatorSource compSource = null;

            if (SortField.FIELD_DOC.Equals(sf))
            {
                compSource = new DocComparatorSource.DocIdDocComparatorSource();
            }
            else if (SortField.FIELD_SCORE.Equals(sf) || sf.Type == SortField.SCORE)
            {
                // we want to do reverse sorting regardless for relevance
                compSource = new ReverseDocComparatorSource(new DocComparatorSource.RelevanceDocComparatorSource());
            }
            else if (sf is BoboCustomSortField)
            {
                BoboCustomSortField custField = (BoboCustomSortField)sf;
                DocComparatorSource src       = custField.GetCustomComparatorSource();
                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.GetDocComparatorSource();
                }
                else
                {
                    // default lucene field
                    logger.Info("doing default lucene sort for: " + sf);
                    compSource = GetNonFacetComparatorSource(sf);
                }
            }
            bool reverse = sf.Reverse;

            if (reverse)
            {
                compSource = new ReverseDocComparatorSource(compSource);
            }
            compSource.IsReverse = reverse;
            return(compSource);
        }
コード例 #3
0
        public SortCollectorImpl(
            DocComparatorSource compSource,
            SortField[] sortFields,
            IBrowsable boboBrowser,
            int offset,
            int count,
            bool doScoring,
            bool fetchStoredFields,
            IEnumerable <string> termVectorsToFetch,
            string[] groupBy,
            int maxPerGroup,
            bool collectDocIdCache)
            : base(sortFields, fetchStoredFields)
        {
            Debug.Assert(offset >= 0 && count >= 0);
            _boboBrowser        = boboBrowser;
            _compSource         = compSource;
            _pqList             = new List <DocIDPriorityQueue>();
            _numHits            = offset + count;
            _offset             = offset;
            _count              = count;
            _totalHits          = 0;
            _totalGroups        = 0;
            _queueFull          = false;
            _doScoring          = doScoring;
            _tmpScoreDoc        = new MyScoreDoc();
            _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.groupByMulti = groupByList.ToArray();
                    this.groupBy      = groupByMulti[0];
                }
                if (this.groupBy != null && _count > 0)
                {
                    if (groupByMulti.Length == 1)
                    {
                        //_currentValueDocMaps = new Int2ObjectOpenHashMap<ScoreDoc>(_count);
                        _currentValueDocMaps  = new Dictionary <int, ScoreDoc>(_count);
                        _facetAccessibleLists = null;
                    }
                    else
                    {
                        _currentValueDocMaps      = null;
                        _facetCountCollectorMulti = new IFacetCountCollector[groupByList.Count - 1];
                        _facetAccessibleLists     = new List <IFacetAccessible> [_facetCountCollectorMulti.Length];
                        for (int i = 0; i < _facetCountCollectorMulti.Length; ++i)
                        {
                            _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
                {
                    _currentValueDocMaps  = null;
                    _facetAccessibleLists = null;
                }
            }
            else
            {
                _currentValueDocMaps  = null;
                _facetAccessibleLists = null;
            }
        }
コード例 #4
0
        public static SortCollector BuildSortCollector(IBrowsable browser, Query q, SortField[] sort,
            int offset, int count, bool forceScoring, bool fetchStoredFields, IEnumerable<string> termVectorsToFetch,
            string[] groupBy, int maxPerGroup, bool collectDocIdCache)
        {
            bool doScoring = forceScoring;
            if (sort == null || sort.Length == 0)
            {
                if (q != null && !(q is MatchAllDocsQuery))
                {
                    sort = new SortField[] { SortField.FIELD_SCORE };
                }
            }

            if (sort == null || sort.Length == 0)
            {
                sort = new SortField[] { SortField.FIELD_DOC };
            }

            IEnumerable<string> facetNames = browser.FacetNames;
            foreach (SortField sf in sort)
            {
                if (sf.Type == SortField.SCORE)
                {
                    doScoring = true;
                    break;
                }
            }

            DocComparatorSource compSource;
            if (sort.Length == 1)
            {
                SortField sf = Convert(browser, sort[0]);
                compSource = GetComparatorSource(browser, sf);
            }
            else
            {
                DocComparatorSource[] compSources = new DocComparatorSource[sort.Length];
                for (int i = 0; i < sort.Length; ++i)
                {
                    compSources[i] = GetComparatorSource(browser, Convert(browser, sort[i]));
                }
                compSource = new MultiDocIdComparatorSource(compSources);
            }
            return new SortCollectorImpl(compSource, sort, browser, offset, count, doScoring, fetchStoredFields, termVectorsToFetch, groupBy, maxPerGroup, collectDocIdCache);
        }
コード例 #5
0
 public BoboCustomSortField(string field, bool reverse, DocComparatorSource factory)
     : base(field, SortField.CUSTOM, reverse)
 {
     _factory = factory;
 }
コード例 #6
0
 public ReverseDocComparatorSource(DocComparatorSource inner)
 {
     _inner = inner;
 }
コード例 #7
0
 public ReverseDocComparatorSource(DocComparatorSource inner)
 {
     _inner = inner;
 }
コード例 #8
0
 public MultiDocIdComparatorSource(DocComparatorSource[] compSources)
 {
     _compSources = compSources;
 }