Project

General

Profile

Revision 178

Added by Matt Jones over 20 years ago

fixed QuerySpecification to produce SQL that does UNION or INTERSECT set operations for query group combinations

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
157 157
    elementStack.push(currentNode); 
158 158
    if (currentNode.getTagName().equals("querygroup")) {
159 159
      QueryGroup currentGroup = new QueryGroup(
160
                                currentNode.getAttribute("booleantype"));
160
                                currentNode.getAttribute("operator"));
161 161
      if (query == null) {
162 162
        query = currentGroup;
163 163
      } else {
......
229 229
    // This determines the returned results
230 230
    self.append("SELECT docid,docname,doctype,doctitle ");
231 231
    self.append("FROM xml_documents WHERE docid IN (");
232
    self.append("SELECT DISTINCT docid FROM xml_nodes WHERE \n");
233 232

  
234
    // This determines the WHERE conditions
233
    // This determines the documents that meet the query conditions
235 234
    self.append(query.printSQL());
236 235

  
237 236
    self.append(") ");
......
267 266

  
268 267
  /** a utility class that represents a group of terms in a query */
269 268
  private class QueryGroup {
270
    private String booleantype = null; // indicates how query terms are combined
271
    private Vector children = null;    // the list of query terms and groups
269
    private String operator = null;  // indicates how query terms are combined
270
    private Vector children = null;  // the list of query terms and groups
272 271

  
273 272
    /** 
274 273
     * construct a new QueryGroup 
275 274
     *
276
     * @param booleantype the boolean conector used to connect query terms 
275
     * @param operator the boolean conector used to connect query terms 
277 276
     *                    in this query group
278 277
     */
279
    public QueryGroup(String booleantype) {
280
      this.booleantype = booleantype;
278
    public QueryGroup(String operator) {
279
      this.operator = operator;
281 280
      children = new Vector();
282 281
    }
283 282

  
......
321 320
        if (first) {
322 321
          first = false;
323 322
        } else {
324
          self.append(" " + booleantype + " ");
323
          self.append(" " + operator + " ");
325 324
        }
326 325
        if (qobject instanceof QueryGroup) {
327 326
          QueryGroup qg = (QueryGroup)qobject;
......
344 343
    public String toString() {
345 344
      StringBuffer self = new StringBuffer();
346 345

  
347
      self.append("  (Query group booleantype=" + booleantype + "\n");
346
      self.append("  (Query group operator=" + operator + "\n");
348 347
      Enumeration en= getChildren();
349 348
      while (en.hasMoreElements()) {
350 349
        Object qobject = en.nextElement();
......
444 443
        searchvalue = casevalue;
445 444
      }
446 445

  
447
      self.append("(");
446
      self.append("SELECT DISTINCT docid FROM xml_nodes WHERE \n");
448 447

  
449 448
      if (pathexpr != null) {
450 449
        self.append(nodedataterm + " LIKE " + "'" + searchvalue + "' ");
......
455 454
        self.append(nodedataterm + " LIKE " + "'" + searchvalue + "' ");
456 455
      }
457 456

  
458
      self.append(") \n");
459

  
460 457
      return self.toString();
461 458
    }
462 459

  
src/edu/ucsb/nceas/metacat/DBQuery.java
126 126
  /** 
127 127
   * routine to search the elements and attributes looking to match query
128 128
   *
129
   * @param queryspec the xml serialization of the query (@see pathquery.dtd)
129
   * @param xmlquery the xml serialization of the query (@see pathquery.dtd)
130 130
   */
131
  public Hashtable findDocuments(Reader queryspec) {
131
  public Hashtable findDocuments(Reader xmlquery) {
132 132
      Hashtable	 docListResult = new Hashtable();
133 133
      PreparedStatement pstmt;
134 134
      String docid = null;
......
139 139

  
140 140
      try {
141 141
        // Get the XML query and covert it into a SQL statment
142
        QuerySpecification qspec = new QuerySpecification(queryspec, 
142
        QuerySpecification qspec = new QuerySpecification(xmlquery, 
143 143
                                   parserName);
144
        System.out.println(qspec.printSQL());
144 145
        pstmt = conn.prepareStatement( qspec.printSQL() );
145 146

  
146 147
        // Execute the SQL query using the JDBC connection

Also available in: Unified diff