Project

General

Profile

« Previous | Next » 

Revision 6035

allow "docid override" queries to include the results of a "normal" query - if the operator is left null, it acts as the usual override, otherwise UNION and INTERSECT modes can be used to either augment or refine the results.
this is for incorporating semantic+spatial+keyword queries into one query operation/result

View differences:

src/edu/ucsb/nceas/metacat/DBQuery.java
86 86
    static final int READ = 4;
87 87
    
88 88
    private String qformat = "xml";
89
    
90
    // are we combining the query with docid list and, if so, using INTERSECT or UNION?
91
    private String operator = null;
89 92

  
90 93
    //private Connection conn = null;
91 94
    private String parserName = null;
......
623 626
      if ( givenDocids == null || givenDocids.size() == 0 ) {
624 627
          query = qspec.printSQL(useXMLIndex);
625 628
      } else {
626
          logMetacat.info("DBQuery.findResultDoclist - docid override " + givenDocids.size());
627
          StringBuffer queryBuffer = new StringBuffer( "SELECT docid,docname,doctype,date_created, date_updated, rev " );
628
          queryBuffer.append( " FROM xml_documents WHERE docid IN (" );
629
    	  // condition for the docids
630
    	  StringBuffer docidCondition = new StringBuffer();
631
    	  docidCondition.append( " docid IN (" );
629 632
          for (int i = 0; i < givenDocids.size(); i++) {  
630
              queryBuffer.append("'");
631
              queryBuffer.append( (String)givenDocids.elementAt(i) );
632
              queryBuffer.append("',");
633
        	  docidCondition.append("'");
634
        	  docidCondition.append( (String)givenDocids.elementAt(i) );
635
        	  docidCondition.append("'");
636
        	  if (i < givenDocids.size()-1) {
637
        		  docidCondition.append(",");
638
        	  }
633 639
          }
634
          // empty string hack 
635
          queryBuffer.append( "'') " );
636
          query = queryBuffer.toString();
640
          docidCondition.append( ") " );
641
		  
642
    	  // include the docids, either exclusively, or in conjuction with the query
643
    	  if (operator == null) {
644
    		  query = "SELECT docid, docname, doctype, date_created, date_updated, rev FROM xml_documents WHERE";
645
              query = query + docidCondition.toString();
646
    	  } else {
647
    		  // start with the keyword query, but add conditions
648
              query = qspec.printSQL(useXMLIndex);
649
              String myOperator = "";
650
              if (!query.endsWith("WHERE")) {
651
	              if (operator.equalsIgnoreCase(QueryGroup.UNION)) {
652
	            	  myOperator =  " OR ";
653
	              }
654
	              else {
655
	            	  myOperator =  " AND ";
656
	              }
657
              }
658
              query = query + myOperator + docidCondition.toString();
659

  
660
    	  }
637 661
      } 
638 662
      String ownerQuery = getOwnerQuery(user);
639 663
      //logMetacat.debug("query: " + query);
......
1918 1942
        return result;
1919 1943
    }//isDataPackageId()
1920 1944

  
1945
    public String getOperator() {
1946
		return operator;
1947
	}
1948

  
1921 1949
    /**
1950
     * Specifies if and how docid overrides should be included in the general query
1951
     * @param operator null, UNION, or INTERSECT (see QueryGroup)
1952
     */
1953
	public void setOperator(String operator) {
1954
		this.operator = operator;
1955
	}
1956

  
1957
	/**
1922 1958
     * Check if the user has the permission to export data package
1923 1959
     *
1924 1960
     * @param conn, the connection
src/edu/ucsb/nceas/metacat/QueryGroup.java
55 55
                                                             // and search path is NOT in path index.
56 56
    private Vector queryGroupsChildren = null;
57 57
    private static Logger logMetacat = Logger.getLogger(QueryGroup.class);
58
    private static String UNION = "UNION";
58
    public static String UNION = "UNION";
59
    public static String INTERSECT = "INTERSECT";
59 60

  
61

  
60 62
    /**
61 63
     * construct a new QueryGroup
62 64
     *

Also available in: Unified diff