Project

General

Profile

« Previous | Next » 

Revision 3047

Added by perry about 18 years ago

Added docid override mechanism to DBQuery. Bypasses the queryspec.printSQL method and creates an optimized docid query in cases (like the spatial query) where you know the docids a priori

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
792 792

  
793 793
	if ( !MetaCatUtil.getOption("runSpatialOption").equals("true") ) {
794 794
        	response.setContentType("text/html");
795
        	out.println("<html> Metacat Spatial Option is turned off <html>");
795
        	out.println("<html> Metacat Spatial Option is turned off </html>");
796 796
        	out.close();
797 797
		return ;
798 798
	}		
......
804 804
        Float _ymax = Float.parseFloat( ((String[]) params.get("YMAX"))[0] );
805 805
        Float _xmin = Float.parseFloat( ((String[]) params.get("XMIN"))[0] );
806 806
        Float _ymin = Float.parseFloat( ((String[]) params.get("YMIN"))[0] );
807

  
808 807
        SpatialQuery sq = new SpatialQuery();
809 808
        Vector docids = sq.filterByBbox( _xmin, _ymin, _xmax, _ymax );
810 809
        logMetacat.info(" --- Spatial Query completed. Passing on the SQuery handler");
811 810

  
812 811
        /*
813
         * Create an squery based on vector of matching docids
812
         * Create an array matching docids
814 813
         */
815 814
        String [] docidArray = new String[docids.size()];
816 815
        docids.toArray(docidArray);
817
        String squery = DocumentIdQuery.createDocidQuery( docidArray );
818
        logMetacat.info("-----------\n" + squery + "\n------------------");
819 816

  
820 817
        /*
821
         * Pass to squery handler
818
         * Create squery string
822 819
         */
820
        String squery = DocumentIdQuery.createDocidQuery( docidArray );
821
        logMetacat.info("-----------\n" + squery + "\n------------------");
823 822
        String[] queryArray = new String[1];
824 823
        queryArray[0] = squery;
825 824
        params.put("query", queryArray);
826 825

  
827
        // qformat
826
        /*
827
         * Determine qformat
828
         */
828 829
        String[] qformatArray = new String[1];
829 830
        try {
830 831
            String _skin = ((String[]) params.get("SKIN"))[0];
......
841 842
        actionArray[0] = "squery";
842 843
        params.put("action", actionArray);
843 844

  
844
        handleSQuery(out, params, response, username, groupnames, sess_id);
845
        /*
846
         * Pass the docids to the DBQuery contructor
847
         */
848
        DBQuery queryobj = new DBQuery(docids);
849
        queryobj.findDocuments(response, out, params, username, groupnames, sess_id);
845 850

  
846 851
  }
847 852

  
848
    /**
849
     * Create a metacat squery for spatial data coordinates.
850
     */
851
    private String createSpatialQuery(float _xmin, float _ymin, float _xmax, float _ymax) {
852
	StringBuffer sb = new StringBuffer();
853
	    
854
	sb.append("<pathquery version=\"1.2\">");
855
	sb.append("<querytitle>Untitled-Search-3</querytitle>");
856
	sb.append("<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN</returndoctype>");
857
	sb.append("<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype>");
858
	sb.append("<returndoctype>-//NCEAS//eml-dataset-2.0//EN</returndoctype>");
859
	sb.append("<returndoctype>-//NCEAS//resource//EN</returndoctype>");
860
	sb.append("<returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype>");
861
	sb.append("<returndoctype>eml://ecoinformatics.org/eml-2.0.1</returndoctype>");
862
	sb.append("<returndoctype>metadata</returndoctype>");
863
	sb.append("<returnfield>dataset/title</returnfield>");
864
	sb.append("<returnfield>originator/individualName/surName</returnfield>");
865
	sb.append("<returnfield>originator/individualName/givenName</returnfield>");
866
	sb.append("<returnfield>originator/organizationName</returnfield>");
867
	sb.append("<returnfield>creator/individualName/surName</returnfield>");
868
	sb.append("<returnfield>creator/individualName/givenName</returnfield>");
869
	sb.append("<returnfield>creator/organizationName</returnfield>");
870
	sb.append("<returnfield>keyword</returnfield>");
871
	sb.append("<returnfield>entityName</returnfield>");
872
	sb.append("<returnfield>idinfo/citation/citeinfo/title</returnfield>");
873
	sb.append("<returnfield>idinfo/citation/citeinfo/origin</returnfield>");
874
	sb.append("<returnfield>idinfo/keywords/theme/themekey</returnfield>");
875
	sb.append("<querygroup operator=\"INTERSECT\">");
876
	sb.append("<queryterm searchmode=\"greater-than\" casesensitive=\"false\">");
877
	sb.append("<value>" + _ymin + "</value>");
878
	sb.append("<pathexpr>northBoundingCoordinate</pathexpr>");
879
	sb.append("</queryterm>");
880
	sb.append("<queryterm searchmode=\"less-than\" casesensitive=\"false\">");
881
	sb.append("<value>" + _ymax + "</value>");
882
	sb.append("<pathexpr>southBoundingCoordinate</pathexpr>");
883
	sb.append("</queryterm>");
884
	sb.append("<queryterm searchmode=\"greater-than\" casesensitive=\"false\">");
885
	sb.append("<value>" + _xmin + "</value>");
886
	sb.append("<pathexpr>eastBoundingCoordinate</pathexpr>");
887
	sb.append("</queryterm>");
888
 	sb.append("<queryterm searchmode=\"less-than\" casesensitive=\"false\">");
889
	sb.append("<value>" + _xmax + "</value>");
890
	sb.append("<pathexpr>westBoundingCoordinate</pathexpr>");
891
	sb.append("</queryterm>");
892
	sb.append("</querygroup>");
893
	sb.append("</pathquery>");
894

  
895
	return sb.toString();
896
    }
897

  
898 853
    // LOGIN & LOGOUT SECTION
899 854
    /**
900 855
     * Handle the login request. Create a new session object. Do user
src/edu/ucsb/nceas/metacat/DBQuery.java
85 85
    /** true if the metacat spatial option is installed **/
86 86
    private final boolean METACAT_SPATIAL = true;
87 87

  
88
    // MPTODO testing
89
    Vector docidOverride = new Vector();
90

  
88 91
    /**
89 92
     * the main routine used to test the DBQuery utility.
90 93
     * <p>
......
198 201
        this.parserName = parserName;
199 202
    }
200 203

  
204
    /**
205
     * 
206
     * Construct an instance of DBQuery Class
207
     * BUT accept a docid Vector that will supersede
208
     * the query.printSQL() method
209
     *
210
     * If a docid Vector is passed in,
211
     * the docids will be used to create a simple IN query 
212
     * without the multiple subselects of the printSQL() method
213
     *
214
     * Using this constructor, we just check for 
215
     * a docidOverride Vector in the findResultDoclist() method
216
     *
217
     * @param docids List of docids to display in the resultset
218
     */
219
    public DBQuery(Vector docids)
220
    {
221
        this.docidOverride = docids;
222
        String parserName = MetaCatUtil.getOption("saxparser");
223
        this.parserName = parserName;
224
    }
201 225

  
202 226
  /**
203 227
   * Method put the search result set into out printerwriter
......
288 312
        	 params.put("isModerator", new String[] {"true"});
289 313
         }
290 314

  
315
         //MPTODO testing
316
         //logMetacat.info("\n\n MPTODO \n\n " + xml.toString() + "\n\n");
317

  
291 318
         trans.transformXMLDocument(xml.toString(), "-//NCEAS//resultset//EN",
292 319
                                 "-//W3C//HTML//EN", qformat, out, params,
293 320
                                 sessionid);
......
412 439
      String updateDate = null;
413 440
      StringBuffer document = null;
414 441
      int rev = 0;
415
      String query = qspec.printSQL(useXMLIndex);
442

  
443
      String query = null;
444

  
445
      /*
446
       * Check the docidOverride Vector
447
       * if defined, we bypass the qspec.printSQL() method
448
       * and contruct a simpler query based on a 
449
       * list of docids rather than a bunch of subselects
450
       */
451
      if ( this.docidOverride.size() == 0 ) {
452
          query = qspec.printSQL(useXMLIndex);
453
      } else {
454
          logMetacat.info("\n\n\n******************* docid override **************\n\n\n");
455
          StringBuffer queryBuffer = new StringBuffer( "SELECT docid,docname,doctype,date_created, date_updated, rev " );
456
          queryBuffer.append( " FROM xml_documents WHERE docid IN (" );
457
          for (int i = 0; i < docidOverride.size(); i++) {  
458
              queryBuffer.append("'");
459
              queryBuffer.append( (String)docidOverride.elementAt(i) );
460
              queryBuffer.append("',");
461
          }
462
          //MPTODO remove trailing "," instead of this empty string hack 
463
          queryBuffer.append( "'') " );
464
          query = queryBuffer.toString();
465
      } 
466

  
416 467
      String ownerQuery = getOwnerQuery(user);
417
      logMetacat.info("query: " + query);
418
      //logMetacat.info("query: "+ownerQuery);
468
      logMetacat.info("\n\n\n query: " + query);
469
      logMetacat.info("\n\n\n owner query: "+ownerQuery);
419 470
      // if query is not the owner query, we need to check the permission
420 471
      // otherwise we don't need (owner has all permission by default)
421 472
      if (!query.equals(ownerQuery))
......
430 481
        } else {
431 482
            query = query + accessQuery.substring(4, accessQuery.length());
432 483
        }
433
        logMetacat.warn(" final query: " + query);
484
        logMetacat.warn("\n\n\n final query: " + query);
434 485
      }
435 486

  
436 487
      double startTime = System.currentTimeMillis() / 1000;
......
619 670
     logMetacat.warn("prepare docid list time: "
620 671
                    + (docListTime - queryExecuteTime));
621 672

  
622
     
623
     //write the persistent spatial dataset
624
     /*
625
	 if(metacatSpatialData != null){
626
		metacatSpatialData.writeTextQueryData();
627
	 }
628
      */
629 673

  
630 674
     return resultsetBuffer;
631 675
    }//findReturnDoclist

Also available in: Unified diff