summaryrefslogtreecommitdiff
path: root/src/assistant/3rdparty/clucene/src/CLucene/index/MultiReader.cpp
blob: 1260d04dc1c9f95d59d49ab7454d7992bcc3df62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
* 
* Distributable under the terms of either the Apache License (Version 2.0) or 
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#include "CLucene/StdHeader.h"
#include "MultiReader.h"

#include "IndexReader.h"
#include "CLucene/document/Document.h"
#include "Terms.h"
#include "SegmentMergeQueue.h"

CL_NS_USE(store)
CL_NS_USE(util)
CL_NS_DEF(index)

MultiReader::MultiReader(IndexReader** subReaders):
  IndexReader(subReaders == NULL || subReaders[0] == NULL ? NULL : subReaders[0]->getDirectory()),
  normsCache(true, true)
{
	initialize(subReaders);
}

MultiReader::MultiReader(Directory* directory, SegmentInfos* sis, IndexReader** subReaders):
	IndexReader(directory, sis, false),
	normsCache(true, true)
{
	initialize(subReaders);
}


MultiReader::~MultiReader() {
//Func - Destructor
//Pre  - true
//Post - The instance has been destroyed all IndexReader instances
//       this instance managed have been destroyed to

	_CLDELETE_ARRAY(ones);
	_CLDELETE_ARRAY(starts);
	
	//Iterate through the subReaders and destroy each reader
	if (subReaders && subReadersLength > 0) {
		for (int32_t i = 0; i < subReadersLength; i++) {
			_CLDELETE(subReaders[i]);
		}
	}
	//Destroy the subReaders array
	_CLDELETE_ARRAY(subReaders);
}

void MultiReader::initialize(IndexReader** subReaders){
  this->subReadersLength = 0;
  this->subReaders = subReaders;

  //count the subReaders size
  if ( subReaders != NULL ){
     while ( subReaders[subReadersLength] != NULL ){
        subReadersLength++;
     }
  }
  _maxDoc        = 0;
  _numDocs       = -1;
  ones           = NULL;

  starts = _CL_NEWARRAY(int32_t,subReadersLength + 1);    // build starts array
  for (int32_t i = 0; i < subReadersLength; i++) {
     starts[i] = _maxDoc;

     // compute maxDocs
     _maxDoc += subReaders[i]->maxDoc();      
     if (subReaders[i]->hasDeletions())
        _hasDeletions = true;
  }
  starts[subReadersLength] = _maxDoc;
}

bool MultiReader::getTermFreqVectors(int32_t n, Array<TermFreqVector*>& result){
	int32_t i = readerIndex(n);        // find segment num
	return subReaders[i]->getTermFreqVectors(n - starts[i], result); // dispatch to segment
}

TermFreqVector* MultiReader::getTermFreqVector(int32_t n, const TCHAR* field){
	int32_t i = readerIndex(n);        // find segment num
	return subReaders[i]->getTermFreqVector(n - starts[i], field);
}


int32_t MultiReader::numDocs() {
	SCOPED_LOCK_MUTEX(THIS_LOCK)
	if (_numDocs == -1) {			  // check cache
	  int32_t n = 0;				  // cache miss--recompute
	  for (int32_t i = 0; i < subReadersLength; i++)
	    n += subReaders[i]->numDocs();		  // sum from readers
	  _numDocs = n;
	}
	return _numDocs;
}

int32_t MultiReader::maxDoc() const {
	return _maxDoc;
}

bool MultiReader::document(int32_t n, CL_NS(document)::Document* doc){
	int32_t i = readerIndex(n);			  // find segment num
	return subReaders[i]->document(n - starts[i],doc);	  // dispatch to segment reader
}

bool MultiReader::isDeleted(const int32_t n) {
	int32_t i = readerIndex(n);			  // find segment num
	return subReaders[i]->isDeleted(n - starts[i]);	  // dispatch to segment reader
}

uint8_t* MultiReader::norms(const TCHAR* field){
	SCOPED_LOCK_MUTEX(THIS_LOCK)
	uint8_t* bytes;
	bytes = normsCache.get(field);
	if (bytes != NULL){
	  return bytes;				  // cache hit
	}
	
	if ( !hasNorms(field) )
		return fakeNorms();
	
	bytes = _CL_NEWARRAY(uint8_t,maxDoc());
	for (int32_t i = 0; i < subReadersLength; i++)
	  subReaders[i]->norms(field, bytes + starts[i]);
	
	//Unfortunately the data in the normCache can get corrupted, since it's being loaded with string
	//keys that may be deleted while still in use by the map. To prevent this field is duplicated
	//and then stored in the normCache
	TCHAR* key = STRDUP_TtoT(field);
	//update cache
	normsCache.put(key, bytes);
	
	return bytes;
}

void MultiReader::norms(const TCHAR* field, uint8_t* result) {
	SCOPED_LOCK_MUTEX(THIS_LOCK)
	uint8_t* bytes = normsCache.get(field);
	if (bytes==NULL && !hasNorms(field)) 
		bytes=fakeNorms();
    
	if (bytes != NULL){                            // cache hit
	   int32_t len = maxDoc();
	   memcpy(result,bytes,len * sizeof(int32_t));
	}
	
	for (int32_t i = 0; i < subReadersLength; i++)      // read from segments
	  subReaders[i]->norms(field, result + starts[i]);
}


void MultiReader::doSetNorm(int32_t n, const TCHAR* field, uint8_t value){
	normsCache.remove(field);                         // clear cache
	int32_t i = readerIndex(n);                           // find segment num
	subReaders[i]->setNorm(n-starts[i], field, value); // dispatch
}

TermEnum* MultiReader::terms() const {
	return _CLNEW MultiTermEnum(subReaders, starts, NULL);
}

TermEnum* MultiReader::terms(const Term* term) const {
	return _CLNEW MultiTermEnum(subReaders, starts, term);
}

int32_t MultiReader::docFreq(const Term* t) const {
	int32_t total = 0;				  // sum freqs in Multi
	for (int32_t i = 0; i < subReadersLength; i++)
	  total += subReaders[i]->docFreq(t);
	return total;
}

TermDocs* MultiReader::termDocs() const {
	TermDocs* ret =  _CLNEW MultiTermDocs(subReaders, starts);
	return ret;
}

TermPositions* MultiReader::termPositions() const {
	TermPositions* ret = (TermPositions*)_CLNEW MultiTermPositions(subReaders, starts);
	return ret;
}

void MultiReader::doDelete(const int32_t n) {
	_numDocs = -1;				  // invalidate cache
	int32_t i = readerIndex(n);			  // find segment num
	subReaders[i]->deleteDocument(n - starts[i]);		  // dispatch to segment reader
	_hasDeletions = true;
}

int32_t MultiReader::readerIndex(const int32_t n) const {	  // find reader for doc n:
	int32_t lo = 0;					   // search starts array
	int32_t hi = subReadersLength - 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 < subReadersLength && starts[mid+1] == midValue) {
	      mid++;                                  // scan to last match
	    }
	    return mid;
	  }
	}
	return hi;
}

bool MultiReader::hasNorms(const TCHAR* field) {
	for (int i = 0; i < subReadersLength; i++) {
		if (subReaders[i]->hasNorms(field)) 
			return true;
	}
	return false;
}
uint8_t* MultiReader::fakeNorms() {
	if (ones==NULL) 
		ones=SegmentReader::createFakeNorms(maxDoc());
	return ones;
}

void MultiReader::doUndeleteAll(){
	for (int32_t i = 0; i < subReadersLength; i++)
		subReaders[i]->undeleteAll();
	_hasDeletions = false;
	_numDocs = -1;
}
void MultiReader::doCommit() {
	for (int32_t i = 0; i < subReadersLength; i++)
	  subReaders[i]->commit();
}

void MultiReader::doClose() {
	SCOPED_LOCK_MUTEX(THIS_LOCK)
	for (int32_t i = 0; i < subReadersLength; i++){
	  subReaders[i]->close();
	}
}


void MultiReader::getFieldNames(FieldOption fldOption, StringArrayWithDeletor& retarray){
    StringArrayWithDeletor temp;
    CLHashList<TCHAR*> hashList;
    for (int32_t i = 0; i < subReadersLength; i++) {
      IndexReader* reader = subReaders[i];
      reader->getFieldNames(fldOption, temp);

      //create a unique list of names.
      StringArrayWithDeletor::iterator itr = temp.begin();
      while ( itr != temp.end() ){
          if ( hashList.find(*itr) == hashList.end() )
            hashList.insert(STRDUP_TtoT(*itr));
          itr++;
      }
    }
    //move the items into the return
    CLHashList<TCHAR*>::iterator itr = hashList.begin();
    while ( itr != hashList.end() ){
      retarray.push_back(*itr);//no need to copy, already done!
      itr++;
    }
}


MultiTermDocs::MultiTermDocs(){
//Func - Default constructor
//       Initialises an empty MultiTermDocs.
//       This constructor is needed to allow the constructor of MultiTermPositions
//       initialise the instance by itself
//Pre  - true
//Post - An empty

	subReaders       = NULL;
	subReadersLength = 0;
	starts        = NULL;
	base          = 0;
	pointer       = 0;
	current       = NULL;
	term          = NULL;
	readerTermDocs   = NULL;
}

MultiTermDocs::MultiTermDocs(IndexReader** r, const int32_t* s){
//Func - Constructor
//Pre  - if r is NULL then rLen must be 0 else if r != NULL then rLen > 0
//       s != NULL
//Post - The instance has been created

	//count readers
	subReadersLength = 0;
	subReaders       = r;
	
	CND_PRECONDITION(s != NULL, "s is NULL");
	
	if ( subReaders != NULL ){
		while ( subReaders[subReadersLength] != NULL )
			subReadersLength++;
	}

	starts        = s;
	base          = 0;
	pointer       = 0;
	current       = NULL;
	term          = NULL;
	
	readerTermDocs   = NULL;

	//Check if there are subReaders
	if(subReaders != NULL && subReadersLength > 0){
	  readerTermDocs = _CL_NEWARRAY(TermDocs*, subReadersLength+1);
	
	  CND_CONDITION(readerTermDocs != NULL,"No memory could be allocated for readerTermDocs");
	
	  //Initialize the readerTermDocs pointer array to NULLs
	  for ( int32_t i=0;i<subReadersLength+1;i++){
	     readerTermDocs[i]=NULL;
	  }
	}
}

MultiTermDocs::~MultiTermDocs(){
//Func - Destructor
//Pre  - true
//Post - The instance has been destroyed

  close();
}


TermPositions* MultiTermDocs::__asTermPositions(){
  return NULL;
}

int32_t MultiTermDocs::doc() const {
  CND_PRECONDITION(current!=NULL,"current==NULL, check that next() was called");
  return base + current->doc();
}
int32_t MultiTermDocs::freq() const {
	CND_PRECONDITION(current!=NULL,"current==NULL, check that next() was called");
	return current->freq();
}

void MultiTermDocs::seek(TermEnum* termEnum){
	seek(termEnum->term(false));
}

void MultiTermDocs::seek( Term* tterm) {
//Func - Resets the instance for a new search
//Pre  - tterm != NULL
//Post - The instance has been reset for a new search

	CND_PRECONDITION(tterm != NULL, "tterm is NULL");
	
	//Assigning tterm is done as below for a reason
	//The construction ensures that if seek is called from within
	//MultiTermDocs with as argument this->term (seek(this->term)) that the assignment
	//will succeed and all referencecounters represent the correct situation
	
	//Get a pointer from tterm and increase its reference counter
	Term *TempTerm = _CL_POINTER(tterm);
	
	//Finialize term to ensure we decrease the reference counter of the instance which term points to
	_CLDECDELETE(term);
	
	//Assign TempTerm to term
	term = TempTerm;
	
	base = 0;
	pointer = 0;
	current = NULL;
}

bool MultiTermDocs::next() {
	if (current != NULL && current->next()) {
	  return true;
	} else if (pointer < subReadersLength) {
	  base = starts[pointer];
	  current = termDocs(pointer++);
	  return next();
	} else
	  return false;
}

int32_t MultiTermDocs::read(int32_t* docs, int32_t* freqs, int32_t length) {
	while (true) {
	  while (current == NULL) {
	    if (pointer < subReadersLength) {		  // try next segment
	      base = starts[pointer];
	      current = termDocs(pointer++);
	    } else {
	      return 0;
	    }
	  }
	  int32_t end = current->read(docs, freqs,length);
	  if (end == 0) {				  // none left in segment
	    current = NULL;
	  } else {					  // got some
	    int32_t b = base;			  // adjust doc numbers
	    for (int32_t i = 0; i < end; i++)
	      docs[i] += b;
	    return end;
	  }
	}
}

bool MultiTermDocs::skipTo(const int32_t target) {
	do {
	  if (!next())
	    return false;
	} while (target > doc());
	return true;
}

void MultiTermDocs::close() {
//Func - Closes all MultiTermDocs managed by this instance
//Pre  - true
//Post - All the MultiTermDocs have been closed


	//Check if readerTermDocs is valid
	if (readerTermDocs){
        TermDocs* curTD = NULL;
        //iterate through the readerTermDocs array
        for (int32_t i = 0; i < subReadersLength; i++) {
            //Retrieve the i-th TermDocs instance
            curTD = readerTermDocs[i];
            
            //Check if it is a valid pointer
            if (curTD != NULL) {
                //Close it
                curTD->close();
                _CLDELETE(curTD);
            }
        }
        
        _CLDELETE_ARRAY(readerTermDocs);
	}
	
	//current previously pointed to a member of readerTermDocs; ensure that
	//it doesn't now point to invalid memory.
	current = NULL;
	base          = 0;
	pointer       = 0;
	
	_CLDECDELETE(term);
}

TermDocs* MultiTermDocs::termDocs(const IndexReader* reader) const {
	TermDocs* ret = reader->termDocs();
	return ret;
}

TermDocs* MultiTermDocs::termDocs(const int32_t i) const {
	if (term == NULL)
	  return NULL;
	TermDocs* result = readerTermDocs[i];
	if (result == NULL){
	  readerTermDocs[i] = termDocs(subReaders[i]);
	  result = readerTermDocs[i];
	}
	result->seek(term);
	
	return result;
}


MultiTermEnum::MultiTermEnum(
  IndexReader** subReaders, const int32_t *starts, const Term* t){
//Func - Constructor
//       Opens all enumerations of all readers
//Pre  - readers != NULL and contains an array of IndexReader instances each responsible for
//       reading a single segment
//       subReadersLength >= 0 and represents the number of readers in the readers array
//       starts is an array of
//Post - An instance of has been created

//Pre  - if readers is NULL then subReadersLength must be 0 else if readers != NULL then subReadersLength > 0
//       s != NULL
//Post - The instance has been created
	
	int32_t subReadersLength = 0;
	if ( subReaders != NULL ){
		while ( subReaders[subReadersLength] != NULL )
			subReadersLength++;
	}
	CND_PRECONDITION(starts != NULL,"starts is NULL");
	
	//Temporary variables
	IndexReader*   reader    = NULL;
	TermEnum* termEnum  = NULL;
	SegmentMergeInfo* smi      = NULL;
	_docFreq = 0;
	_term = NULL;
	queue                      = _CLNEW SegmentMergeQueue(subReadersLength);
	
	CND_CONDITION (queue != NULL, "Could not allocate memory for queue");
	
	//iterate through all the readers
	for ( int32_t i=0;i<subReadersLength;i++ ) {
		//Get the i-th reader
		reader = subReaders[i];
		
		//Check if the enumeration must start from term t
		if (t != NULL) {
			//termEnum is an enumeration of terms starting at or after the named term t
			termEnum = reader->terms(t);
		}else{
			//termEnum is an enumeration of all the Terms and TermInfos in the set.
			termEnum = reader->terms();
		}

		//Instantiate an new SegmentMerginfo
		smi = _CLNEW SegmentMergeInfo(starts[i], termEnum, reader);
		
		// Note that in the call termEnum->getTerm(false) below false is required because
		// otherwise a reference is leaked. By passing false getTerm is
		// ordered to return an unowned reference instead. (Credits for DSR)
		if (t == NULL ? smi->next() : termEnum->term(false) != NULL){
			// initialize queue
			queue->put(smi);
		} else{
			//Close the SegmentMergeInfo
			smi->close();
			//And have it deleted
			_CLDELETE(smi);
		}
	}
	
	//Check if the queue has elements
	if (t != NULL && queue->size() > 0) {
		next();
	}
}

MultiTermEnum::~MultiTermEnum(){
//Func - Destructor
//Pre  - true
//Post - All the resource have been freed and the instance has been deleted

	//Close the enumeration
	close();
	
	//Delete the queue
	_CLDELETE(queue);
}

bool MultiTermEnum::next(){
//Func - Move the current term to the next in the set of enumerations
//Pre  - true
//Post - Returns true if term has been moved to the next in the set of enumerations
//       Returns false if this was not possible

	SegmentMergeInfo* top = queue->top();
	if (top == NULL) {
	    _CLDECDELETE(_term); 
	    _term = NULL;
	    return false;
	}
	
	//The getTerm method requires the client programmer to indicate whether he
	// owns the returned reference, so we can discard ours
	// right away.
	_CLDECDELETE(_term); 
	
	//Assign term the term of top and make sure the reference counter is increased
	_term = _CL_POINTER(top->term);
	_docFreq = 0;
	
	//Find the next term
	while (top != NULL && _term->compareTo(top->term) == 0) {
		//don't delete, this is the top
		queue->pop(); 
		// increment freq
		_docFreq += top->termEnum->docFreq();	  
		if (top->next()){
			// restore queue
			queue->put(top);				  
		}else{
			// done with a segment
			top->close();				  
			_CLDELETE(top);
		}
		top = queue->top();
	}
	
	return true;
}


Term* MultiTermEnum::term() {
//Func - Returns the current term of the set of enumerations
//Pre  - pointer is true or false and indicates if the reference counter
//       of term must be increased or not
//       next() must have been called once!
//Post - pointer = true -> term has been returned with an increased reference counter
//       pointer = false -> term has been returned

	return _CL_POINTER(_term);
}

Term* MultiTermEnum::term(bool pointer) {
  	if ( pointer )
    	return _CL_POINTER(_term);
    else
    	return _term;
}

int32_t MultiTermEnum::docFreq() const {
//Func - Returns the document frequency of the current term in the set
//Pre  - termInfo != NULL
//       next() must have been called once
//Post  - The document frequency of the current enumerated term has been returned

  return _docFreq;
}


void MultiTermEnum::close() {
//Func - Closes the set of enumerations in the queue
//Pre  - queue holds a valid reference to a SegmentMergeQueue
//Post - The queue has been closed all SegmentMergeInfo instance have been deleted by
//       the closing of the queue
//       term has been finalized and reset to NULL

	// Needed when this enumeration hasn't actually been exhausted yet
	_CLDECDELETE(_term);
	
	//Close the queue This will destroy all SegmentMergeInfo instances!
	queue->close();

}





MultiTermPositions::MultiTermPositions(IndexReader** r, const int32_t* s){
//Func - Constructor
//Pre  - if r is NULL then rLen must be 0 else if r != NULL then rLen > 0
//       s != NULL
//Post - The instance has been created

	subReaders       = r;
	subReadersLength    = 0;
	if ( subReaders != NULL ){
		while ( subReaders[subReadersLength] != NULL )
		subReadersLength ++ ;
	}
	
	CND_PRECONDITION(s != NULL, "s is NULL");
	
	starts        = s;
	base          = 0;
	pointer       = 0;
	current       = NULL;
	term          = NULL;
	
	readerTermDocs   = NULL;

	//Check if there are readers
	if(subReaders != NULL && subReadersLength > 0){
		readerTermDocs = (TermDocs**)_CL_NEWARRAY(SegmentTermPositions*,subReadersLength);
		
		CND_CONDITION(readerTermDocs != NULL,"No memory could be allocated for readerTermDocs");
		
		//Initialize the readerTermDocs pointer array
		for ( int32_t i=0;i<subReadersLength;i++){
			readerTermDocs[i]=NULL;
		}
	}
}


TermDocs* MultiTermPositions::__asTermDocs(){
  return (TermDocs*) this;
}
TermPositions* MultiTermPositions::__asTermPositions(){
  return (TermPositions*) this;
}


TermDocs* MultiTermPositions::termDocs(const IndexReader* reader) const {
// Here in the MultiTermPositions class, we want this->current to always
// be a SegmentTermPositions rather than merely a SegmentTermDocs.
// To that end, we override the termDocs(IndexReader&) method to produce
// a SegmentTermPositions via the underlying reader's termPositions method
// rather merely producing a SegmentTermDocs via the reader's termDocs
// method.

	TermPositions* tp = reader->termPositions();
	TermDocs* ret = tp->__asTermDocs();
	
	CND_CONDITION(ret != NULL,
	    "Dynamic downcast in MultiTermPositions::termDocs from"
	    " TermPositions to TermDocs failed."
	  );
	return ret;
	}
	
int32_t MultiTermPositions::nextPosition() {
	//Func -
	//Pre  - current != NULL
	//Post -
	CND_PRECONDITION(current != NULL,"current is NULL");
	
	TermPositions* curAsTP = current->__asTermPositions();
	
	CND_CONDITION(curAsTP != NULL,
	    "Dynamic downcast in MultiTermPositions::nextPosition from"
	    " SegmentTermDocs to TermPositions failed."
	)
	return curAsTP->nextPosition();
}


CL_NS_END