n
in the array
* used to construct this searcher. */
int32_t MultiSearcher::subSearcher(int32_t n) const{
// replace w/ call to Arrays.binarySearch in Java 1.2
int32_t lo = 0; // search starts array
int32_t hi = searchablesLen - 1; // for first element less
// than n, return its index
while (hi >= lo) {
int32_t mid = (lo + hi) >> 1;
int32_t midValue = starts[mid];
if (n < midValue)
hi = mid - 1;
else if (n > midValue)
lo = mid + 1;
else{ // found a match
while (mid+1 < searchablesLen && starts[mid+1] == midValue) {
mid++; // scan to last match
}
return mid;
}
}
return hi;
}
/** Returns the document number of document n
within its
* sub-index. */
int32_t MultiSearcher::subDoc(int32_t n) const{
return n - starts[subSearcher(n)];
}
int32_t MultiSearcher::maxDoc() const{
return _maxDoc;
}
TopDocs* MultiSearcher::_search(Query* query, Filter* filter, const int32_t nDocs) {
HitQueue* hq = _CLNEW HitQueue(nDocs);
int32_t totalHits = 0;
for (int32_t i = 0; i < searchablesLen; i++) { // search each searcher
TopDocs* docs = searchables[i]->_search(query, filter, nDocs);
totalHits += docs->totalHits; // update totalHits
ScoreDoc** scoreDocs = docs->scoreDocs;
int32_t j = 0;
while (scoreDocs[j] != NULL ){
//for ( j {@link HitCollector#collect(int32_t,float_t)} is called for every non-zero * scoring document. * *
Applications should only use this if they need all of the
* matching documents. The high-level search API ({@link
* Searcher#search(Query)}) is usually more efficient, as it skips
* non-high-scoring hits.
*
* @param query to match documents
* @param filter if non-null, a bitset used to eliminate some documents
* @param results to receive hits
*/
void MultiSearcher::_search(Query* query, Filter* filter, HitCollector* results){
for (int32_t i = 0; i < searchablesLen; i++) {
/* DSR:CL_BUG: Old implementation leaked and was misconceived. We need
** to have the original HitCollector ($results) collect *all* hits;
** the MultiHitCollector instantiated below serves only to adjust
** (forward by starts[i]) the docNo passed to $results.
** Old implementation instead created a sort of linked list of
** MultiHitCollectors that applied the adjustments in $starts
** cumulatively (and was never deleted). */
HitCollector *docNoAdjuster = _CLNEW MultiHitCollector(results, starts[i]);
searchables[i]->_search(query, filter, docNoAdjuster);
_CLDELETE(docNoAdjuster);
}
}
TopFieldDocs* MultiSearcher::_search (Query* query, Filter* filter, const int32_t n, const Sort* sort){
FieldDocSortedHitQueue* hq = NULL;
int32_t totalHits = 0;
for (int32_t i = 0; i < searchablesLen; i++) { // search each searcher
TopFieldDocs* docs = searchables[i]->_search (query, filter, n, sort);
if (hq == NULL){
hq = _CLNEW FieldDocSortedHitQueue (docs->fields, n);
docs->fields = NULL; //hit queue takes fields
}
totalHits += docs->totalHits; // update totalHits
ScoreDoc** scoreDocs = docs->scoreDocs;
bool done=false;
for(int32_t j = 0;j