1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator; 2 3 import com.daffodilwoods.database.resource.DException; 4 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator; 5 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass; 6 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 7 import com.daffodilwoods.database.utility.*; 8 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 9 10 23 24 public class Rank2FTIterator extends RankSuccesiveLocation { 25 26 public Rank2FTIterator(_Iterator[] fullTextIndex0, _Iterator[] locationIndex0,_Reference[] fpkReference0,FieldBase[] keyWords0) throws DException { 27 fullTextIndex = fullTextIndex0; 28 locationIndex = locationIndex0; 29 pkColumn = GeneralPurposeStaticClass.getColumnDetails("pk"); 30 documentIdColumn = GeneralPurposeStaticClass.getColumnDetails("documentId"); 31 locationColumn = GeneralPurposeStaticClass.getColumnDetails("location"); 32 fpkReference = fpkReference0; 33 keyWords =keyWords0; 34 } 35 36 44 public boolean alignLocationForward() throws DException { 45 Object [] fpkValues = setValues(); 46 setLocationIteratorsForward(); 47 Object value = locationIndex[0].getColumnValues(locationColumn); 48 Object oldValue = value; 49 boolean areSuccesive = true; 50 for(int ii = 1 ; ii < locationIndex.length; ii++){ 51 boolean flag = locationIndex[ii].seekFromTopRelative(new Object [] {fpkValues[ii], value}); 52 if(!flag) 53 return false; 54 value = locationIndex[ii].getColumnValues(locationColumn); 55 if( compare(value,oldValue) > 1) 56 areSuccesive = false; 57 } 58 if(areSuccesive) 59 return false; 60 return !alignSuccesiveLocationForward(fpkValues, locationIndex.length -1); 61 } 62 63 71 public boolean alignLocationBackward() throws DException { 72 Object [] fpkValues = setValues(); 73 setLocationIteratorsBackward(); 74 int length = locationIndex.length; 75 Object value = locationIndex[length-1] 76 .getColumnValues(locationColumn); 77 Object oldValue = value; 78 boolean isSuccessive = true; 79 for(int ii = length-2 ; ii >= 0; ii--){ 80 if(!locationIndex[ii].seekFromBottomRelative(new Object [] {fpkValues[ii], value})) 81 return false; 82 value = locationIndex[ii].getColumnValues(locationColumn); 83 if( compare(oldValue,value) > 1) 84 isSuccessive = false; 85 } 86 if(isSuccessive) 87 return false; 88 return !alignSuccesiveLocationBackward(fpkValues, length -1); 89 } 90 91 98 private void setLocationIteratorsForward() throws DException { 99 if(!locationIndex[0].first()) 100 throw new DException("DSE0", new Object []{"Illegal happening"}); 101 for (int i = 1; i < locationIndex.length; i++) { if(locationIndex[i].first()) 103 locationIndex[i].previous(); 104 } 105 } 106 107 114 private void setLocationIteratorsBackward() throws com.daffodilwoods.database.resource.DException{ 115 int length = locationIndex.length; 116 if(!locationIndex[length-1].last()) 117 throw new DException("DSE0", new Object []{"Illegal happening"}); 118 for (int i = length - 2 ; i >= 0; i--) { if(locationIndex[i].last()) 120 locationIndex[i].next(); 121 } 122 } 123 124 public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{ 125 } 126 127 public String toString(){ 128 String str = "Rank2FTIterator"; 129 str += "[FullTextIndex"+fullTextIndex[0] 130 + "][locationIndex"+locationIndex[0] 131 +"]"; 132 return str; 133 } 134 } 135 | Popular Tags |