Changeset 2415 for TI01-discovery


Ignore:
Timestamp:
17/04/07 17:02:36 (13 years ago)
Author:
mpritcha
Message:

Tweaks to orderBy. Still not right yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/SearchAgent.java

    r2259 r2415  
    5050        String term = ""; 
    5151        String orderBy;                                                 // representation used in WSDL e.g. "date", "dataCentre" 
    52         String orderByField = "document($name)/dgMetadata/dgMetadataRecord/dgDataEntity/dgDataSummary/dgDataCoverage/dgTemporalCoverage/DateRange/DateRangeStart";                              // xquery / xpath expression representing orderBy field 
     52        String orderByField = "document($name)/moles:dgMetadata/moles:dgMetadataRecord/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage/moles:dgTemporalCoverage/moles:DateRange/moles:DateRangeStart"; 
     53        String orderByFunction = ""; 
     54        // xquery / xpath expression representing orderBy field 
    5355        String orderByDirection = "ascending";  //default orderBy direction 
    5456        // TODO ...add orderByDirection (and to WSDL) 
     
    120122                if ( s.equals("date") ) 
    121123                { 
    122                         this.orderByField = "document($name)/dgMetadata/dgMetadataRecord/dgDataEntity/dgDataSummary/dgDataCoverage/dgTemporalCoverage/DateRange/DateRangeStart"; 
     124                        this.orderByField = "document($name)/moles:dgMetadata/moles:dgMetadataRecord/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage/moles:dgTemporalCoverage/moles:DateRange/moles:DateRangeStart"; 
    123125                } 
    124126 
     
    126128                { 
    127129                        // TODO ...not correct yet (should look up Organisation moles record) 
    128                         this.orderByField = "document($name)/dgMetadata/dgMetadataRecord/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder/dgOrganisationID/repositoryIdentifier"; 
     130                        this.orderByField = "document($name)/moles:dgMetadata/moles:dgMetadataRecord/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder/moles:dgOrganisationID/moles:repositoryIdentifier"; 
    129131                } 
    130132        } 
     
    136138        public void setOrderByDirection(String s) 
    137139        { 
    138                 this.orderByDirection = s; 
     140                if ( s.equals("descnding") ) 
     141                { 
     142                        this.orderByDirection = "descending"; 
     143                } 
     144                else  
     145                { 
     146                        this.orderByDirection = s; 
     147                } 
    139148        } 
    140149 
     
    333342                        xqueryStr = xqueryStr.replaceFirst("__subst_scope__", this.getScopesAsString() ); 
    334343                        //"/dgMetadata/dgMetadataRecord/dgDataEntity/dgDataSummary/dgDataCoverage/dgTemporalCoverage/DateRange/DateRangeStart" 
    335                         xqueryStr = xqueryStr.replaceFirst("__subst_orderByField__", this.orderByField); 
     344 
     345                        // orderByField contains $ chars etc so needs special treatment to avoid "java.lang.IllegalArgumentException: Illegal group reference" when replacing 
     346                        String orderByFieldReplace = Matcher.quoteReplacement(this.orderByField); 
     347                        xqueryStr = xqueryStr.replaceAll("__subst_orderByField__", orderByFieldReplace); //NB replaceAll cos more than 1! 
     348                        xqueryStr = xqueryStr.replaceFirst("__subst_orderByDirection__", this.orderByDirection); 
    336349                         
    337350                        // Construct the search clause for spatio temporal search, if necessary 
     
    415428 
    416429                        xqueryStr = xqueryStr.replaceFirst("__subst_spatioTempWhereClause__", whereClause ); 
    417                         xqueryStr = xqueryStr.replaceFirst("__subst_orderByDirection__", this.orderByDirection); 
    418430 
    419431                        xqueryStr = xqueryStr.replaceFirst("__subst_doTerm__", this.doTerm ? "fn:true()" : "fn:false()"); 
     
    422434                        xqueryStr = xqueryStr.replaceFirst("__subst_doScope__", this.doScope ? "fn:true()" : "fn:false()"); 
    423435                         
    424                         // orderByField contains $ chars etc so needs special treatment to avoid "java.lang.IllegalArgumentException: Illegal group reference" when replacing 
    425                         String orderByFieldReplace = Matcher.quoteReplacement(this.orderByField); 
    426                         xqueryStr = xqueryStr.replaceAll("__subst_orderByField__", orderByFieldReplace); //NB replaceAll cos more than 1!  
    427  
    428                         //System.out.println("Xquery was \n" + xqueryStr); 
     436                        System.out.println("Xquery was \n" + xqueryStr); 
    429437 
    430438                        queryParams.addElement( xqueryStr.getBytes("UTF-8") );  
     
    540548"   \"__subst_spatioTempWhereClause__\" \n"+ 
    541549"}; \n"+ 
    542 "declare function local:getOrderByDirection() as xs:string { \n"+ 
    543 "   \"__subst_orderByDirection__\" \n"+ 
    544 "}; \n"+ 
    545550"declare function local:doSpatioTemp() as xs:boolean { \n"+ 
    546551"   __subst_doSpatioTemp__ \n"+ 
     
    552557"   __subst_doOrderBy__ \n"+ 
    553558"}; \n"+ 
     559 
     560"declare function local:orderBy($arg1 as item()* )as item()* { \n"+ 
     561"       if ( local:doOrderBy() ) then ( \n"+ 
     562"               for $i in $arg1 \n"+ 
     563"               let $coll := '/db/discovery/moles' \n"+ 
     564"               let $thisdoc := $i \n"+ 
     565"               let $name := string-join( ($coll , $thisdoc), '/' ) \n"+ 
     566"               let $field := __subst_orderByField__ \n"+ 
     567"               order by $field __subst_orderByDirection__ \n"+ 
     568"               return $i \n"+ 
     569"       ) \n"+ 
     570"       else $arg1 \n"+ 
     571"}; \n"+ 
     572 
    554573"declare function local:doScope() as xs:boolean { \n"+ 
    555574"   __subst_doScope__ \n"+ 
     
    583602"        where document($name)/moles:dgMetadata/moles:dgMetadataRecord/moles:dgStructuredKeyword[moles:dgValidTerm &= local:getScope() and voclib:spot-vocab($voclib:ndg_data_provider_vocab, moles:dgValidTermID/moles:ParentListID)] \n"+ 
    584603"      return $i \n"+ 
    585 "   ) \n"+ 
    586 "   else $arg1 \n"+ 
    587 "}; \n"+ 
    588 "declare function local:orderBy($arg1 as item()* )as item()* { \n"+ 
    589 "   if ( local:doOrderBy() ) then ( \n"+ 
    590 "      if ( local:getOrderByDirection() = \"descending\" ) then ( \n"+ 
    591 "         for $i in $arg1 \n"+ 
    592 "         let $coll := '/db/discovery/moles' \n"+ 
    593 "         let $thisdoc := $i \n"+ 
    594 "         let $name := string-join( ($coll , $thisdoc), '/' ) \n"+ 
    595 "         order by document($name)/dgMetadata/dgMetadataRecord/dgDataEntity/dgDataSummary/dgDataCoverage/dgTemporalCoverage/DateRange/DateRangeStart descending \n"+ 
    596 "         return $i \n"+ 
    597 "      ) \n"+ 
    598 "      else ( \n"+ 
    599 "         for $i in $arg1 \n"+ 
    600 "         let $coll := '/db/discovery/moles' \n"+ 
    601 "         let $thisdoc := $i \n"+ 
    602 "         let $name := string-join( ($coll , $thisdoc), '/' ) \n"+ 
    603 "         order by document($name)/dgMetadata/dgMetadataRecord/dgDataEntity/dgDataSummary/dgDataCoverage/dgTemporalCoverage/DateRange/DateRangeStart ascending \n"+ 
    604 "         return $i \n"+ 
    605 "      ) \n"+ 
    606604"   ) \n"+ 
    607605"   else $arg1 \n"+ 
Note: See TracChangeset for help on using the changeset viewer.