Project

General

Profile

« Previous | Next » 

Revision 3392

Added by Jing Tao about 17 years ago

Fixed bug that if user choose to many documents in spatial query, the result set will be 0.

View differences:

src/edu/ucsb/nceas/metacat/DBQuery.java
77 77
    /** true if the metacat spatial option is installed **/
78 78
    private final boolean METACAT_SPATIAL = true;
79 79

  
80
    /** useful if you just want to grab a list of docids **/
80
    /** useful if you just want to grab a list of docids. Since the docids can be very long,
81
         it is a vector of vector  **/
81 82
    Vector docidOverride = new Vector();
82 83
    
83 84
    // a hash table serves as query reuslt cache. Key of hashtable
......
219 220
     */
220 221
    public DBQuery(Vector docids)
221 222
    {
222
        this.docidOverride = docids;
223
    	// since the query will be too long to be handled, so we divided the 
224
    	// docids vector into couple vectors.
225
    	int size = (new Integer(MetaCatUtil.getOption("app_resultsetsize"))).intValue();
226
    	logMetacat.info("The size of select doicds is "+docids.size());
227
    	logMetacat.info("The application result size in metacat.properties is "+size);
228
    	Vector subset = new Vector();
229
    	if (docids != null && docids.size() > size)
230
    	{
231
    		int index = 0;
232
    		for (int i=0; i< docids.size(); i++)
233
    		{
234
    			
235
    			if (index < size)
236
    			{  	
237
    				subset.add(docids.elementAt(i));
238
    				index ++;
239
    			}
240
    			else
241
    			{
242
    				docidOverride.add(subset);
243
    				subset = new Vector();
244
    				subset.add(docids.elementAt(i));
245
    			    index = 1;
246
    			}
247
    		}
248
    		if (!subset.isEmpty())
249
    		{
250
    			docidOverride.add(subset);
251
    		}
252
    		
253
    	}
254
    	else
255
    	{
256
    		this.docidOverride.add(docids);
257
    	}
258
        
223 259
        String parserName = MetaCatUtil.getOption("saxparser");
224 260
        this.parserName = parserName;
225 261
    }
......
419 455

  
420 456
        //print out the search result
421 457
        // search the doc list
422
        StringBuffer resultContent = findResultDoclist(qspec, out, user, groups,
423
                                      dbconn, useXMLIndex, pagesize, pagestart, 
424
                                      sessionid);
458
        Vector givenDocids = new Vector();
459
        StringBuffer resultContent = new StringBuffer();
460
        if (docidOverride == null || docidOverride.size() == 0)
461
        {
462
        	logMetacat.info("Not in map query");
463
        	resultContent = findResultDoclist(qspec, out, user, groups,
464
                    dbconn, useXMLIndex, pagesize, pagestart, 
465
                    sessionid, givenDocids);
466
        }
467
        else
468
        {
469
        	logMetacat.info("In map query");
470
        	// since docid can be too long to be handled. We divide it into several parts
471
        	for (int i= 0; i<docidOverride.size(); i++)
472
        	{
473
        	   logMetacat.info("in loop===== "+i);
474
        		givenDocids = (Vector)docidOverride.elementAt(i);
475
        		StringBuffer subset = findResultDoclist(qspec, out, user, groups,
476
                        dbconn, useXMLIndex, pagesize, pagestart, 
477
                        sessionid, givenDocids);
478
        		resultContent.append(subset);
479
        	}
480
        }
481
           
425 482
        resultset.append(resultContent);
426 483
      } //try
427 484
      catch (IOException ioe)
......
464 521
                                      PrintWriter out,
465 522
                                      String user, String[]groups,
466 523
                                      DBConnection dbconn, boolean useXMLIndex,
467
                                      int pagesize, int pagestart, String sessionid)
524
                                      int pagesize, int pagestart, String sessionid, Vector givenDocids)
468 525
                                      throws Exception
469 526
    {
470 527
      StringBuffer resultsetBuffer = new StringBuffer();
......
508 565
       * and contruct a simpler query based on a 
509 566
       * list of docids rather than a bunch of subselects
510 567
       */
511
      if ( this.docidOverride.size() == 0 ) {
568
      if ( givenDocids == null || givenDocids.size() == 0 ) {
512 569
          query = qspec.printSQL(useXMLIndex);
513 570
      } else {
514
          logMetacat.info("*** docid override " + this.docidOverride.size());
571
          logMetacat.info("*** docid override " + givenDocids.size());
515 572
          StringBuffer queryBuffer = new StringBuffer( "SELECT docid,docname,doctype,date_created, date_updated, rev " );
516 573
          queryBuffer.append( " FROM xml_documents WHERE docid IN (" );
517
          for (int i = 0; i < docidOverride.size(); i++) {  
574
          for (int i = 0; i < givenDocids.size(); i++) {  
518 575
              queryBuffer.append("'");
519
              queryBuffer.append( (String)docidOverride.elementAt(i) );
576
              queryBuffer.append( (String)givenDocids.elementAt(i) );
520 577
              queryBuffer.append("',");
521 578
          }
522 579
          // empty string hack 
......
554 611
   	      //System.out.println("==========the string from cache is "+cachedResult);
555 612
   	      if (cachedResult != null)
556 613
   	      {
614
   	    	logMetacat.info("resutl from cache !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
557 615
   	    	 if (out != null)
558 616
   	         {
559 617
   	             out.println(cachedResult);

Also available in: Unified diff