Revision 3225
Added by Jing Tao over 17 years ago
src/edu/ucsb/nceas/metacat/QueryGroup.java | ||
---|---|---|
44 | 44 |
private String operator = null; // indicates how query terms are combined |
45 | 45 |
private Vector children = null; // the list of query terms and groups |
46 | 46 |
private int countPercentageSearchItem = 0; |
47 |
private Vector queryTermsWithSameValue = null;//this two dimension vectors. |
|
48 |
//will hold query terms which has same search value. |
|
49 |
private Vector queryTerms = null;//this vector only holds query terms without same search value. |
|
47 | 50 |
private static Logger logMetacat = Logger.getLogger(QueryGroup.class); |
48 | 51 |
|
49 | 52 |
/** |
... | ... | |
55 | 58 |
public QueryGroup(String operator) { |
56 | 59 |
this.operator = operator; |
57 | 60 |
children = new Vector(); |
61 |
queryTermsWithSameValue = new Vector(); |
|
62 |
queryTerms = new Vector(); |
|
58 | 63 |
} |
59 | 64 |
|
60 | 65 |
/** |
... | ... | |
73 | 78 |
*/ |
74 | 79 |
public void addChild(QueryTerm qterm) { |
75 | 80 |
children.add((Object)qterm); |
81 |
handleNewQueryTerms(qterm); |
|
82 |
|
|
76 | 83 |
} |
77 | 84 |
|
78 | 85 |
/** |
... | ... | |
167 | 174 |
self.append(" )\n"); |
168 | 175 |
return self.toString(); |
169 | 176 |
} |
177 |
|
|
178 |
/* |
|
179 |
* When a new QueryTerm come, first we need to compare it to |
|
180 |
* the queryTerm vector, which contains queryTerm that doesn't |
|
181 |
* have same search value to any other queryTerm. Here is algorithm. |
|
182 |
* 1) If new QueryTerm find a QueryTerm in queryTerms which has same search value, |
|
183 |
* them create a new vector which contain both QueryTerms and add the new vector |
|
184 |
* to two-dimention vector queryTermsWithSameValue, and remove the QueryTerm which |
|
185 |
* was in queryTerm. |
|
186 |
* 2) If new QueryTerm couldn't find a QueryTerm in queryTerms which has same search value, |
|
187 |
* then search queryTermsWithSameValue, to see if this vector already has the search value. |
|
188 |
* 2.1) if has the search value, add the new QueryTerm to the queryTermsWithSameValue. |
|
189 |
* 2.2) if hasn't, add the new QueryTerm to queryTerms vector. |
|
190 |
*/ |
|
191 |
private void handleNewQueryTerms(QueryTerm newTerm) |
|
192 |
{ |
|
193 |
if (newTerm != null) |
|
194 |
{ |
|
195 |
for (int i=0; i<queryTerms.size(); i++) |
|
196 |
{ |
|
197 |
QueryTerm term = (QueryTerm)queryTerms.elementAt(i); |
|
198 |
if (term != null && term.hasSameSearchValue(newTerm)) |
|
199 |
{ |
|
200 |
// find a target which has same search value |
|
201 |
Vector newSameValueVector = new Vector(); |
|
202 |
newSameValueVector.add(term); |
|
203 |
newSameValueVector.addElement(newTerm); |
|
204 |
queryTermsWithSameValue.add(newSameValueVector); |
|
205 |
queryTerms.remove(i); |
|
206 |
return; |
|
207 |
} |
|
208 |
} |
|
209 |
// no same search value was found in queryTerms. |
|
210 |
// then we need search queryTermsWithSameValue |
|
211 |
for (int i=0; i<queryTermsWithSameValue.size(); i++) |
|
212 |
{ |
|
213 |
Vector sameValueVec = (Vector)queryTermsWithSameValue.elementAt(i); |
|
214 |
// we only compare the first query term |
|
215 |
QueryTerm term = (QueryTerm)sameValueVec.elementAt(0); |
|
216 |
if (term != null && term.hasSameSearchValue(newTerm)) |
|
217 |
{ |
|
218 |
sameValueVec.add(newTerm); |
|
219 |
return; |
|
220 |
} |
|
221 |
} |
|
222 |
// both queryTerms and queryTermsWithSameValue don't have the search value, |
|
223 |
// add this newTerm to queryTerms |
|
224 |
queryTerms.add(newTerm); |
|
225 |
} |
|
226 |
|
|
227 |
} |
|
170 | 228 |
} |
Also available in: Unified diff
Add new data structure and method to handle query terms which have same search value.