private TopDocs ExecuteQuery(Query documentQuery, int start, int pageSize, Sort sort) { if (sort == null && _indexHasBoostedFields == false && IsBoostedQuery(documentQuery) == false) { if (pageSize == int.MaxValue || pageSize >= _searcher.MaxDoc) // we want all docs, no sorting required { var gatherAllCollector = new GatherAllCollector(Math.Min(pageSize, _searcher.MaxDoc)); _searcher.Search(documentQuery, gatherAllCollector, _state); return(gatherAllCollector.ToTopDocs()); } var noSortingCollector = new NonSortingCollector(Math.Abs(pageSize + start)); _searcher.Search(documentQuery, noSortingCollector, _state); return(noSortingCollector.ToTopDocs()); } var minPageSize = GetPageSize(_searcher, (long)pageSize + start); if (sort != null) { _searcher.SetDefaultFieldSortScoring(true, false); try { return(_searcher.Search(documentQuery, null, minPageSize, sort, _state)); } finally { _searcher.SetDefaultFieldSortScoring(false, false); } } return(_searcher.Search(documentQuery, null, minPageSize, _state)); }
private TopDocs ExecuteQuery(Query documentQuery, int start, int pageSize, Sort sort) { if (sort == null && _indexHasBoostedFields == false && IsBoostedQuery(documentQuery) == false) { if (pageSize == int.MaxValue) // we want all docs, no sorting required { var gatherAllCollector = new GatherAllCollector(); _searcher.Search(documentQuery, gatherAllCollector); return(gatherAllCollector.ToTopDocs()); } var noSortingCollector = new NonSortingCollector(Math.Abs(pageSize + start)); _searcher.Search(documentQuery, noSortingCollector); return(noSortingCollector.ToTopDocs()); } var absFullPage = Math.Abs(pageSize + start); // need to protect against ridiculously high values of pageSize + start that overflow var minPageSize = Math.Max(absFullPage, 1); if (sort != null) { _searcher.SetDefaultFieldSortScoring(true, false); try { return(_searcher.Search(documentQuery, null, minPageSize, sort)); } finally { _searcher.SetDefaultFieldSortScoring(false, false); } } return(_searcher.Search(documentQuery, null, minPageSize)); }