Revision 2522
Added by sgarg over 19 years ago
src/edu/ucsb/nceas/metacat/QueryTerm.java | ||
---|---|---|
189 | 189 |
} |
190 | 190 |
} |
191 | 191 |
|
192 |
self.append("SELECT DISTINCT docid FROM xml_nodes WHERE "); |
|
193 |
self.append(searchexpr); |
|
194 |
if (pathexpr != null) { |
|
195 | 192 |
|
196 |
// use XML Index |
|
197 |
if (useXMLIndex) { |
|
198 |
if (!hasAttributeInPath(pathexpr)) { |
|
199 |
// without attributes in path |
|
200 |
self.append("AND parentnodeid IN "); |
|
201 |
} else { |
|
202 |
// has a attribute in path |
|
203 |
String attributeName = QuerySpecification |
|
193 |
// to check xml_path_index can be used |
|
194 |
boolean usePathIndex = false; |
|
195 |
|
|
196 |
// if pathexpr has been specified in metacat.properties for indexing |
|
197 |
if(pathexpr != null){ |
|
198 |
if(MetaCatUtil.pathsForIndexing.contains(pathexpr)){ |
|
199 |
usePathIndex = true; |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
if(usePathIndex){ |
|
204 |
// using xml_path_index table..... |
|
205 |
self.append("SELECT DISTINCT docid FROM xml_path_index WHERE "); |
|
206 |
self.append(searchexpr); |
|
207 |
self.append("AND path LIKE '" + pathexpr + "' "); |
|
208 |
|
|
209 |
} else { |
|
210 |
// using xml_nodes and xml_index tables |
|
211 |
|
|
212 |
self.append("SELECT DISTINCT docid FROM xml_nodes WHERE "); |
|
213 |
self.append(searchexpr); |
|
214 |
if (pathexpr != null) { |
|
215 |
|
|
216 |
// use XML Index |
|
217 |
if (useXMLIndex) { |
|
218 |
if (!hasAttributeInPath(pathexpr)) { |
|
219 |
// without attributes in path |
|
220 |
self.append("AND parentnodeid IN "); |
|
221 |
} |
|
222 |
else { |
|
223 |
// has a attribute in path |
|
224 |
String attributeName = QuerySpecification |
|
204 | 225 |
.getAttributeName(pathexpr); |
205 |
self.append("AND nodetype LIKE 'ATTRIBUTE' AND nodename LIKE '" |
|
206 |
+ attributeName + "' "); |
|
207 |
// and the path expression includes element content other than |
|
208 |
// just './' or '../' |
|
209 |
if ((!pathexpr.startsWith(QuerySpecification.ATTRIBUTESYMBOL)) && |
|
210 |
(!pathexpr.startsWith("./" + QuerySpecification.ATTRIBUTESYMBOL)) && |
|
211 |
(!pathexpr.startsWith("../" + QuerySpecification.ATTRIBUTESYMBOL))) { |
|
226 |
self.append( |
|
227 |
"AND nodetype LIKE 'ATTRIBUTE' AND nodename LIKE '" |
|
228 |
+ attributeName + "' "); |
|
229 |
// and the path expression includes element content other than |
|
230 |
// just './' or '../' |
|
231 |
if ( (!pathexpr.startsWith(QuerySpecification. |
|
232 |
ATTRIBUTESYMBOL)) && |
|
233 |
(!pathexpr.startsWith("./" + |
|
234 |
QuerySpecification.ATTRIBUTESYMBOL)) && |
|
235 |
(!pathexpr.startsWith("../" + |
|
236 |
QuerySpecification.ATTRIBUTESYMBOL))) { |
|
212 | 237 |
|
213 |
self.append("AND parentnodeid IN "); |
|
214 |
pathexpr = QuerySpecification |
|
215 |
.newPathExpressionWithOutAttribute(pathexpr); |
|
238 |
self.append("AND parentnodeid IN "); |
|
239 |
pathexpr = QuerySpecification |
|
240 |
.newPathExpressionWithOutAttribute(pathexpr); |
|
241 |
} |
|
216 | 242 |
} |
243 |
self.append( |
|
244 |
"(SELECT nodeid FROM xml_index WHERE path LIKE " |
|
245 |
+ "'" + pathexpr + "') "); |
|
217 | 246 |
} |
218 |
self.append("(SELECT nodeid FROM xml_index WHERE path LIKE " |
|
219 |
+ "'" + pathexpr + "') "); |
|
220 |
} else { |
|
221 |
// without using XML Index; using nested statements instead |
|
222 |
self.append("AND parentnodeid IN "); |
|
223 |
self.append(useNestedStatements(pathexpr)); |
|
247 |
else { |
|
248 |
// without using XML Index; using nested statements instead |
|
249 |
self.append("AND parentnodeid IN "); |
|
250 |
self.append(useNestedStatements(pathexpr)); |
|
251 |
} |
|
224 | 252 |
} |
225 |
} else if ((value.trim()).equals("%")) {
|
|
226 |
//if pathexpr is null and search value is %, is a |
|
227 |
// percentageSearchItem |
|
228 |
// the count number will be increase one |
|
229 |
countPercentageSearchItem++; |
|
253 |
else if ( (value.trim()).equals("%")) {
|
|
254 |
//if pathexpr is null and search value is %, is a
|
|
255 |
// percentageSearchItem
|
|
256 |
// the count number will be increase one
|
|
257 |
countPercentageSearchItem++;
|
|
230 | 258 |
|
259 |
} |
|
231 | 260 |
} |
232 | 261 |
|
233 | 262 |
return self.toString(); |
Also available in: Unified diff
Adding code to check if all the paths being searched for indexed are not. If all paths are indexed, the code will use xml_path_index instead of using xml_nodes and xml_index