numberOfRetrievedDocuments = 0;
// The posting list min heap for minimum selection
// longs are kept, as these contain both the docid (high byte)
// and the corresponding query term array index (low byte)
final LongPriorityQueue postingHeap = new LongHeapPriorityQueue();
final int queryLength = queryTermsToMatchList.size();
// The posting list iterator array (one per term) and initialization
IterablePosting postingListArray[] = new IterablePosting[queryLength];
for (int i = 0; i < queryLength; i++) {
LexiconEntry lexiconEntry = queryTermsToMatchList.get(i).getValue();
if(logger.isDebugEnabled()) logger.debug((i + 1) + ": " + queryTermStrings[i].trim() + " with " + lexiconEntry.getDocumentFrequency() + " documents (TF is " + lexiconEntry.getFrequency() + ").");
postingListArray[i] = invertedIndex.getPostings((BitIndexPointer)lexiconEntry);
postingListArray[i].next();
long docid = postingListArray[i].getId();
assert(docid != -1);
postingHeap.enqueue((docid << 32) + i);
}
boolean targetResultSetSizeReached = false;
final Queue<CandidateResult> candidateResultList = new PriorityQueue<CandidateResult>();
int currentDocId = selectMinimumDocId(postingHeap);
IterablePosting currentPosting = null;
double threshold = 0.0d;
//int scored = 0;
//while not end of all posting lists
while (currentDocId != -1) {
// We create a new candidate for the doc id considered
CandidateResult currentCandidate = new CandidateResult(currentDocId);
int currentPostingListIndex = (int) (postingHeap.firstLong() & 0xFFFF), nextDocid;
//System.err.println("currentDocid="+currentDocId+" currentPostingListIndex="+currentPostingListIndex);
currentPosting = postingListArray[currentPostingListIndex];
//scored++;
do {
assignScore(currentPostingListIndex, wm[currentPostingListIndex], currentCandidate, currentPosting);
long newDocid = postingListArray[currentPostingListIndex].next();
postingHeap.dequeueLong();
if (newDocid != IterablePosting.EOL)
postingHeap.enqueue((newDocid << 32) + currentPostingListIndex);
else if (postingHeap.isEmpty())
break;
long elem = postingHeap.firstLong();
currentPostingListIndex = (int) (elem & 0xFFFF);
currentPosting = postingListArray[currentPostingListIndex];
nextDocid = (int) (elem >>> 32);
} while (nextDocid == currentDocId);