KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > fulltext > dql > condition > OrWords


1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.condition;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.database.sqlinitiator._Order;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator;
6 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dml.
7
    _FullTextIndexInformation;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.set.
9
    UnionAllIterator;
10 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator.
11
    Rank1FTIterator;
12 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator.
13
    Rank2FTIterator;
14 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator.
15
    Rank3FTIterator;
16 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator.
17
    Rank4FTIterator;
18 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
19 import com.daffodilwoods.daffodildb.server.sql99.common.
20
    GeneralPurposeStaticClass;
21 import com.daffodilwoods.daffodildb.server.sql99.common.Datatypes;
22 import com.daffodilwoods.daffodildb.utils.field.FieldBase;
23 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator.AnyKeyWordsIterator;
24
25 /**
26      * This class represents plan which generated when search pattern is combination
27  * of two search pattern, combined with logically OR operator.It provides
28      * functionality to get resultset which is used to get desired documents in which
29  * either or both search pattern is present.plan generated will be optimized.
30  * optimized plan:-plan is optimized if it will provide resultset based on
31      * Rank algorithm.According to Rank Iterator ResultSet gives record in following
32  * Order:-
33  * resultset first gives those record which contain all search pattern + same sequence +zero gap
34  * then after that gives those record which contain all search pattern + same sequence + gap greater then zero
35  * then after that gives those record which contain all search pattern + different in sequence.
36  * then after that gives those record which contain either one of two serach pattern
37  * <p>Title: </p>
38  * <p>Description: </p>
39  * <p>Copyright: Copyright (c) 2003</p>
40  * <p>Company: </p>
41  * @author not attributable
42  * @version 1.0
43  */

44
45 public class OrWords
46     implements _Word {
47   /**
48    * list of word that form complete search pattern ,which is to be searched.
49    */

50   WordRepresentation[] words;
51   /**
52    * name of column against which search pattern is searched.
53    */

54   String JavaDoc columnName;
55
56   private _Order order;
57
58   public OrWords(WordRepresentation[] words0) {
59     words = words0;
60   }
61
62   /**
63    * this method is used to get type of plan which is required by paln merger
64    * to merged two plan either with Logically AND and OR
65    * @return type of plan
66    * @throws DException
67    */

68   public int getType() throws DException {
69     return PredicateConstant.orWords;
70   }
71
72   /**
73    * It is required to get columnName of searched column against which search
74    * pattern is searched.
75    * @return columnName
76    * @throws DException
77    */

78   public String JavaDoc getColumn() throws DException {
79     return columnName = words[0].getColumn();
80   }
81
82   /**
83    * It is used to set columnName of searched column against which search
84    * paatern is searched.
85    * @param colName
86    * @throws DException
87    */

88   public void setColumn(String JavaDoc colName) throws DException {
89     for (int i = 0; i < words.length; i++) {
90       words[i].setColumn(colName);
91     }
92   }
93
94   /**
95    * this method required to get list of word that form complete search pattern,which is to be searched.
96    * @return
97    * @throws DException
98    */

99   public WordRepresentation[] getWord() throws DException {
100     return words;
101   }
102
103   /**
104    * It allows user to obtain resultset of this plan. Resultset is used for
105    * navigating records.ORWord plan generates resultset which is union of 4
106    * resultsets:-
107    * 1. Resultset contains All Search pattern + sameSequence + Zero gap
108    * 2. Resultsetcontains Allserach + sameSequence + gap>0
109    * 3. AllKeywords + different Sequence but not same sequence.
110    * 4. Resultset contain either one keyword present.
111    * In this way Resultset provides record in optimized way.
112    * @param session
113    * @return _Iterator
114    * @throws DException
115    */

116
117   public _Iterator execute(Object JavaDoc session) throws DException {
118     int length = words.length;
119     _Iterator tokenIterator[] = new _Iterator[length];
120     _Iterator locationIterator[] = new _Iterator[length];
121     _Reference fpkReference[] = new _Reference[length];
122     FieldBase[] KeyWords = new FieldBase[length];
123     for (int i = 0; i < length; i++) {
124       tokenIterator[i] = words[i].getTokenIterator(session);
125       locationIterator[i] = words[i].getLocationIterator(session);
126       fpkReference[i] = words[i].getFpkReference();
127       KeyWords[i] = (FieldBase) words[i].getKeyWords();
128
129     }
130     _Iterator rank1 = new Rank1FTIterator(tokenIterator, locationIterator,
131                                           fpkReference, KeyWords);
132     _Iterator rank2 = new Rank2FTIterator(tokenIterator, locationIterator,
133                                           fpkReference, KeyWords);
134     _Iterator rank3 = new Rank3FTIterator(tokenIterator, locationIterator,
135                                           fpkReference, KeyWords);
136     _Iterator rank4 = new Rank4FTIterator(tokenIterator, locationIterator,
137                                           fpkReference, KeyWords);
138     return getUnionIterator(rank1, rank2, rank3, rank4);
139   }
140
141   private _Iterator getUnionIterator(_Iterator rank1, _Iterator rank2,
142                                      _Iterator rank3, _Iterator rank4) throws
143       DException {
144     int[] appropriateDataType = new int[] {
145         Datatypes.LONGSIZE};
146     _Reference[] leftReferences = new _Reference[] {
147         GeneralPurposeStaticClass.getColumnDetails("documentId")};
148     _Reference[] rightReferences = new _Reference[] {
149         GeneralPurposeStaticClass.getColumnDetails("documentId")};
150     _Reference[] orderLeftColumnDetails = new _Reference[] {
151         GeneralPurposeStaticClass.getColumnDetails("documentId")};
152     _Reference[] orderRightColumnDetails = new _Reference[] {
153         GeneralPurposeStaticClass.getColumnDetails("documentId")};
154     UnionAllIterator iter = new UnionAllIterator(rank1, rank2, leftReferences,
155                                                  rightReferences,
156                                                  appropriateDataType,
157                                                  appropriateDataType,
158                                                  orderLeftColumnDetails,
159                                                  orderRightColumnDetails);
160     _Reference[] leftReferences1 = new _Reference[] {
161         GeneralPurposeStaticClass.getColumnDetails("documentId")};
162     _Reference[] rightReferences1 = new _Reference[] {
163         GeneralPurposeStaticClass.getColumnDetails("documentId")};
164     _Reference[] orderLeftColumnDetails1 = new _Reference[] {
165         GeneralPurposeStaticClass.getColumnDetails("documentId")};
166     _Reference[] orderRightColumnDetails1 = new _Reference[] {
167         GeneralPurposeStaticClass.getColumnDetails("documentId")};
168     UnionAllIterator iter1 = new UnionAllIterator(rank3, rank4, leftReferences1,
169                                                   rightReferences1,
170                                                   appropriateDataType,
171                                                   appropriateDataType,
172                                                   orderLeftColumnDetails1,
173                                                   orderRightColumnDetails1);
174     _Reference[] leftReferences2 = new _Reference[] {
175         GeneralPurposeStaticClass.getColumnDetails("documentId")};
176     _Reference[] rightReferences2 = new _Reference[] {
177         GeneralPurposeStaticClass.getColumnDetails("documentId")};
178     _Reference[] orderLeftColumnDetails2 = new _Reference[] {
179         GeneralPurposeStaticClass.getColumnDetails("documentId")};
180     _Reference[] orderRightColumnDetails2 = new _Reference[] {
181         GeneralPurposeStaticClass.getColumnDetails("documentId")};
182     return new UnionAllIterator(iter, iter1, leftReferences2, rightReferences2,
183                                 appropriateDataType, appropriateDataType,
184                                 orderLeftColumnDetails2,
185                                 orderRightColumnDetails2);
186
187   }
188
189   public double getCost() throws DException {
190     return 0.0;
191   }
192
193   public double getCost(Object JavaDoc session) throws DException {
194     return 0.0;
195   }
196
197   public double getEstimatedRow() throws DException {
198     return 1;
199   }
200
201   public void setOrder(_Order order) throws DException {
202     this.order = order;
203   }
204
205   public _Order getOrder() throws DException {
206     return order;
207   }
208
209   /**
210    * This method is required to get resultset on every word in serach pattern which is
211    * to be searched. ResultSet of every word provide desired document
212    * in which that search pattern is present.
213    * @param session
214    * @return _Iterator[]
215    * @throws DException
216    */

217   private _Iterator[] getTokenIterator(Object JavaDoc session) throws DException {
218     int length = words.length;
219     _Iterator tokenIterator[] = new _Iterator[length];
220     for (int i = 0; i < length; i++) {
221       tokenIterator[i] = words[i].getTokenIterator(session);
222     }
223     return tokenIterator;
224   }
225
226   /**
227    * Returns the single words.
228    * @param session
229    * @return FieldBase
230    * @throws DException
231    */

232   private FieldBase[] getKeyWords(Object JavaDoc session) throws DException {
233     int length = words.length;
234     FieldBase[] KeyWords = new FieldBase[length];
235     for (int i = 0; i < length; i++) {
236       KeyWords[i] = (FieldBase) words[i].getKeyWords();
237     }
238     return KeyWords;
239   }
240
241   /**
242    * This method is needed when sorted resultset is required on documentid.
243    * It is different from execute method.It returns documents in sorted order
244    * whereas execute method returns documents based on the rank algorithm in
245    * which case resultset is not sorted on documentid.
246    * @param indexTable
247    * @return _Iterator
248    * @throws DException
249    */

250   public _Iterator executeForSortedResult(Object JavaDoc indexTable) throws DException {
251     _Iterator tokenIterator[] = getTokenIterator(indexTable);
252     FieldBase keyWord[] = getKeyWords(indexTable);
253     AnyKeyWordsIterator iter = new AnyKeyWordsIterator(
254         tokenIterator, keyWord);
255     return iter;
256   }
257
258 }
259
Popular Tags