38 |
38 |
import java.util.Vector;
|
39 |
39 |
import java.util.Enumeration;
|
40 |
40 |
|
|
41 |
import org.apache.log4j.Logger;
|
|
42 |
|
41 |
43 |
/** a utility class that represents a group of terms in a query */
|
42 |
44 |
public class QueryGroup {
|
43 |
45 |
private String operator = null; // indicates how query terms are combined
|
44 |
46 |
private Vector children = null; // the list of query terms and groups
|
45 |
47 |
private int countPercentageSearchItem = 0;
|
|
48 |
private static Logger logMetacat = Logger.getLogger(QueryGroup.class);
|
|
49 |
|
46 |
50 |
/**
|
47 |
51 |
* construct a new QueryGroup
|
48 |
52 |
*
|
... | ... | |
92 |
96 |
StringBuffer queryString = new StringBuffer();
|
93 |
97 |
|
94 |
98 |
boolean first = true;
|
95 |
|
|
|
99 |
|
96 |
100 |
Enumeration en= getChildren();
|
97 |
101 |
while (en.hasMoreElements()) {
|
98 |
102 |
Object qobject = en.nextElement();
|
99 |
103 |
if (qobject instanceof QueryGroup) {
|
100 |
104 |
QueryGroup qg = (QueryGroup)qobject;
|
101 |
105 |
String queryGroupSQL = qg.printSQL(useXMLIndex);
|
|
106 |
logMetacat.info("In QueryGroup.printSQL.. found a QueryGroup: "
|
|
107 |
+ queryGroupSQL);
|
102 |
108 |
|
103 |
109 |
if (first) {
|
104 |
110 |
first = false;
|
105 |
111 |
} else {
|
106 |
112 |
if(!queryString.toString().equals("") && queryGroupSQL != null &&!queryGroupSQL.equals("")){
|
107 |
113 |
queryString.append(" " + operator + " ");
|
108 |
|
}
|
109 |
|
queryString.append(queryGroupSQL);
|
110 |
|
}
|
111 |
|
// count percerntage number
|
112 |
|
int count = qg.getPercentageSymbolCount();
|
113 |
|
countPercentageSearchItem = countPercentageSearchItem + count;
|
|
114 |
}
|
|
115 |
}
|
|
116 |
queryString.append(queryGroupSQL);
|
|
117 |
|
|
118 |
// count percerntage number
|
|
119 |
int count = qg.getPercentageSymbolCount();
|
|
120 |
countPercentageSearchItem = countPercentageSearchItem + count;
|
114 |
121 |
} else if (qobject instanceof QueryTerm) {
|
115 |
122 |
QueryTerm qt = (QueryTerm)qobject;
|
116 |
123 |
String termQueryString = qt.printSQL(useXMLIndex);
|
|
124 |
logMetacat.info("In QueryGroup.printSQL.. found a QueryGroup: "
|
|
125 |
+ termQueryString);
|
117 |
126 |
if(!(qt.getSearchMode().equals("contains") && qt.getValue().equals("%"))){
|
118 |
127 |
if (first) {
|
119 |
128 |
first = false;
|
... | ... | |
137 |
146 |
self.append(queryString.toString());
|
138 |
147 |
self.append(")");
|
139 |
148 |
}
|
|
149 |
|
|
150 |
logMetacat.info("In QueryGroup.printSQL.. final query returned is: "
|
|
151 |
+ self.toString());
|
140 |
152 |
return self.toString();
|
141 |
153 |
}
|
142 |
154 |
|
Fixed a bug in QueryGroup which prevented QueryGroup from appending itself to the sql query when no queryTerm is present.