| 1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator; 2 3 import com.daffodilwoods.database.resource.DException; 4 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 5 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator; 7 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass; 8 import com.daffodilwoods.database.utility.*; 9 import com.daffodilwoods.daffodildb.utils.GetByteComparator; 10 import java.util.Arrays ; 11 12 25 public class Rank4FTIterator extends AnyWordsAbstractIterator { 26 27 public Rank4FTIterator(_Iterator[] fullTextIndex0, _Iterator[] locationIndex0,_Reference[] fpkReference0,FieldBase[] keyWord0) throws DException { 28 fullTextIndex = fullTextIndex0; 29 locationIndex = locationIndex0; 30 pkColumn = GeneralPurposeStaticClass.getColumnDetails("pk"); 31 documentIdColumn = GeneralPurposeStaticClass.getColumnDetails("documentId"); 32 locationColumn = GeneralPurposeStaticClass.getColumnDetails("location"); 33 fpkReference = fpkReference0; 34 keyWords =keyWord0; 35 state = INVALIDSTATE; 36 } 37 38 public static boolean testing; 39 40 47 public boolean first() throws DException { 48 testing = true; 49 boolean allFalse = true; 50 for (int i = 0; i < fullTextIndex.length; i++) 51 if (fullTextIndex[i].first()) 52 allFalse = false; 53 direction = true; 54 state = VALIDSTATE; 55 boolean first = allFalse ? false : allSameWithSmallest() ? next() : true; 56 state = first ? VALIDSTATE : AFTERLAST; 57 return first; 58 } 59 60 66 public boolean next() throws DException { 67 switch(state) { 68 case INVALIDSTATE : 69 throw new DException("DSE4116",null); 70 case BEFOREFIRST : 71 return first(); 72 case AFTERLAST : 73 return false; 74 } 75 boolean next = direction ? nextWithForwardDirection() : 76 nextWithOppositeDirection(); 77 state = next ? VALIDSTATE : AFTERLAST; 78 return next; 79 } 80 81 91 private boolean nextWithForwardDirection() throws DException { 92 boolean[] smallest = getSmallest(); 93 for (int i = 0; i < fullTextIndex.length; i++) 94 if (smallest[i]) 95 fullTextIndex[i].next(); 96 boolean allFalse = allFalse(); 97 return allFalse ? false : allSameWithSmallest() ? next() : true; 98 } 99 100 108 private boolean nextWithOppositeDirection() throws DException { 109 boolean allFalse = true; 110 for (int i = 0; i < fullTextIndex.length; i++) 111 if(fullTextIndex[i].next()) 112 allFalse = false; 113 if (allFalse) 114 return false; 115 if (allSameWithSmallest()) 116 return nextWithOppositeDirection(); 117 boolean[] smallest = getSmallest(); 118 for (int i = 0; i < fullTextIndex.length; i++) 119 if (!smallest[i]) 120 fullTextIndex[i].previous(); 121 return true; 122 } 123 124 130 public boolean previous() throws DException { 131 switch (state) { 132 case INVALIDSTATE: 133 throw new DException("DSE4116", null); 134 case AFTERLAST: 135 return last(); 136 case BEFOREFIRST: 137 return false; 138 } 139 boolean prev = !direction ? previousWithBackwardDirection() 140 : previousWithOppositeDirection(); 141 state = prev ? VALIDSTATE : BEFOREFIRST; 142 return prev; 143 } 144 145 155 private boolean previousWithBackwardDirection() throws DException { 156 boolean[] largest = getLargest(); 157 for (int i = 0; i < fullTextIndex.length; i++){ 158 if (largest[i]) 159 fullTextIndex[i].previous(); 160 } 161 return allFalse() ? false : allSameWithLargest() ? previous() : true; 162 } 163 164 172 private boolean previousWithOppositeDirection() throws DException { 173 boolean allFalse = true; 174 for (int i = 0; i < fullTextIndex.length; i++) 175 if(fullTextIndex[i].previous()) 176 allFalse = false; 177 if (allFalse) 178 return false; 179 if (allSameWithLargest()) 180 return previousWithOppositeDirection(); 181 boolean[] largest = getLargest(); 182 for (int i = 0; i < fullTextIndex.length; i++) 183 if (!largest[i]) 184 fullTextIndex[i].next(); 185 return true; 186 } 187 188 195 public boolean last() throws DException { 196 boolean allFalse = true; 197 for (int i = 0; i < fullTextIndex.length; i++) 198 if (fullTextIndex[i].last()) 199 allFalse = false; 200 direction = false; 201 state = VALIDSTATE; 202 boolean last = allFalse ? false : allSameWithLargest() ? previous() : true; 203 state = last ? VALIDSTATE : BEFOREFIRST; 204 return last; 205 } 206 207 public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{ 208 } 209 210 public String toString(){ 211 String str = "Rank4FTIterator"; 212 str += "[FullTextIndex"+fullTextIndex[0] 213 +"]"; 214 return str; 215 } 216 } 217 | Popular Tags |