private int Compare(ScoreDoc doc1, ScoreDoc doc2) { int cmp = comparator.Compare(doc1, doc2); if (cmp != 0) { return(-cmp); } else { return(doc2.Doc - doc1.Doc); } }
public override void Collect(int doc) { ++_totalHits; if (groupBy != null) { if (_facetCountCollectorMulti != null) { for (int i = 0; i < _facetCountCollectorMulti.Length; ++i) { if (_facetCountCollectorMulti[i] != null) { _facetCountCollectorMulti[i].Collect(doc); } } if (_count > 0) { float score = (_doScoring ? _scorer.Score() : 0.0f); // NightOwl888: The _collectDocIdCache setting seems to put arrays into // memory, but then do nothing with the arrays. Seems wasteful and unnecessary. //if (_collectDocIdCache) //{ // if (_totalHits > _docIdCacheCapacity) // { // _currentDocIdArray = intarraymgr.Get(BLOCK_SIZE); // docidarraylist.Add(_currentDocIdArray); // if (_doScoring) // { // _currentScoreArray = floatarraymgr.Get(BLOCK_SIZE); // scorearraylist.Add(_currentScoreArray); // } // _docIdCacheCapacity += BLOCK_SIZE; // _docIdArrayCursor = 0; // } // _currentDocIdArray[_docIdArrayCursor] = doc; // if (_doScoring) // _currentScoreArray[_docIdArrayCursor] = score; // ++_docIdArrayCursor; // ++_currentContext.length; //} } return; } else { //if (_facetCountCollector != null) //_facetCountCollector.collect(doc); if (_count > 0) { float score = (_doScoring ? _scorer.Score() : 0.0f); // NightOwl888: The _collectDocIdCache setting seems to put arrays into // memory, but then do nothing with the arrays. Seems wasteful and unnecessary. //if (_collectDocIdCache) //{ // if (_totalHits > _docIdCacheCapacity) // { // _currentDocIdArray = intarraymgr.Get(BLOCK_SIZE); // docidarraylist.Add(_currentDocIdArray); // if (_doScoring) // { // _currentScoreArray = floatarraymgr.Get(BLOCK_SIZE); // scorearraylist.Add(_currentScoreArray); // } // _docIdCacheCapacity += BLOCK_SIZE; // _docIdArrayCursor = 0; // } // _currentDocIdArray[_docIdArrayCursor] = doc; // if (_doScoring) // _currentScoreArray[_docIdArrayCursor] = score; // ++_docIdArrayCursor; // ++_currentContext.length; //} _tmpScoreDoc.Doc = doc; _tmpScoreDoc.Score = score; if (!_queueFull || _currentComparator.Compare(_bottom, _tmpScoreDoc) > 0) { int order = groupBy.GetFacetData <FacetDataCache>(_currentReader).OrderArray.Get(doc); ScoreDoc pre = _currentValueDocMaps.Get(order); if (pre != null) { if (_currentComparator.Compare(pre, _tmpScoreDoc) > 0) { ScoreDoc tmp = pre; _bottom = _currentQueue.Replace(_tmpScoreDoc, pre); _currentValueDocMaps.Put(order, _tmpScoreDoc); _tmpScoreDoc = tmp; } } else { if (_queueFull) { MyScoreDoc tmp = (MyScoreDoc)_bottom; _currentValueDocMaps.Remove(groupBy.GetFacetData <FacetDataCache>(tmp.reader).OrderArray.Get(tmp.Doc)); _bottom = _currentQueue.Replace(_tmpScoreDoc); _currentValueDocMaps.Put(order, _tmpScoreDoc); _tmpScoreDoc = tmp; } else { ScoreDoc tmp = new MyScoreDoc(doc, score, _currentQueue, _currentReader); _bottom = _currentQueue.Add(tmp); _currentValueDocMaps.Put(order, tmp); _queueFull = (_currentQueue.size >= _numHits); } } } } } } else { if (_count > 0) { float score = (_doScoring ? _scorer.Score() : 0.0f); if (_queueFull) { _tmpScoreDoc.Doc = doc; _tmpScoreDoc.Score = score; if (_currentComparator.Compare(_bottom, _tmpScoreDoc) > 0) { ScoreDoc tmp = _bottom; _bottom = _currentQueue.Replace(_tmpScoreDoc); _tmpScoreDoc = tmp; } } else { _bottom = _currentQueue.Add(new MyScoreDoc(doc, score, _currentQueue, _currentReader)); _queueFull = (_currentQueue.size >= _numHits); } } } if (this.Collector != null) { this.Collector.Collect(doc); } }