private static boolean textTerm =false;
public static void testIndexIterator() throws IOException{
IndexReader firstIndexReader =firstIndex.getReader();
IndexReader secondIndexReader =secondIndex.getReader(1000);
IndexIterator firstIterator = null;
IndexIterator secondIterator = null;
for(int i = 0;i<firstIndex.numberOfTerms;i++){
try{
System.out.println("term: " + i);
firstIterator = firstIndexReader.documents(i);
secondIterator = !textTerm?secondIndexReader.documents(i):secondIndexReader.documents(firstIndex.termMap.list().get(i));
/** Compare hasNext*/
Assert.assertEquals(firstIterator.hasNext(), secondIterator.hasNext());
/** Compare frequency*/
Assert.assertEquals(firstIterator.frequency(), secondIterator.frequency());
/** Compare positions & count*/
while(firstIterator.hasNext()){
int fr = firstIterator.nextDocument();
int sr = secondIterator.nextDocument();
Assert.assertEquals(fr,sr);
/** Compare count*/
Assert.assertEquals(firstIterator.count(), secondIterator.count());
int[] firstPos = new int[1000];
int[] secondPos = new int[1000];
int fRet = firstIterator.positions(firstPos);
int sRet = secondIterator.positions(secondPos);
System.out.println(fRet + " " + sRet);
Assert.assertTrue(fRet == sRet);
for(int j = 0;j<fRet;j++)
Assert.assertEquals(firstPos[j],secondPos[j]);
}
/** Compare positions int[] positionArray()*/
while(firstIterator.hasNext()){
secondIterator.next();
int []firstPos = firstIterator.positionArray();
int []secondPos = secondIterator.positionArray();
Assert.assertTrue(firstPos.length == secondPos.length);
for(int j = 0;j<firstPos.length;j++)
Assert.assertTrue(firstPos[j] == secondPos[j]);
}
/** Compare IntIterator from positions() method */
firstIterator = firstIndexReader.documents(i);
secondIterator = !textTerm?secondIndexReader.documents(i):secondIndexReader.documents(firstIndex.termMap.list().get(i));
while(firstIterator.hasNext()){
firstIterator.next();
secondIterator.next();
IntIterator firstIntIt = firstIterator.positions();
IntIterator secondIntIt = secondIterator.positions();
while(firstIntIt.hasNext()){
Assert.assertEquals(firstIntIt.nextInt(),secondIntIt.nextInt());
}
Assert.assertEquals(firstIntIt.skip(2),secondIntIt.skip(2));
if(firstIntIt.hasNext()){
Assert.assertEquals(firstIntIt.nextInt(),secondIntIt.nextInt());
}
Assert.assertEquals(firstIntIt.skip(9999999),secondIntIt.skip(9999999));
if(firstIntIt.hasNext()){
Assert.assertEquals(firstIntIt.nextInt(),secondIntIt.nextInt());
}
}
/** Compare IntervalIterator from Interval() method */
firstIterator = firstIndexReader.documents(i);
secondIterator = !textTerm?secondIndexReader.documents(i):secondIndexReader.documents(firstIndex.termMap.list().get(i));
while(firstIterator.hasNext()){
firstIterator.next();
secondIterator.next();
/** Compare position IntIterator*/
IntervalIterator firstIntervalIt = firstIterator.intervalIterator(firstIndex);
IntervalIterator secondIntervalIt = secondIterator.intervalIterator(secondIndex);
while(firstIntervalIt.hasNext()){
Interval firstIntv = firstIntervalIt.nextInterval();
Interval secondIntv = secondIntervalIt.nextInterval();
System.out.println("left:" + firstIntv.left + " " + "right:" + firstIntv.right);