Changeset 833 for MDRepository


Ignore:
Timestamp:
11/02/10 22:25:15 (14 years ago)
Author:
ljo
Message:

cmd-model.xql - searchRetrieve query rewrite first step.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDRepository/trunk/xquery/cmd-model.xqm

    r831 r833  
    8080      util:eval(fn:concat("$collection", $sanitized-query, "/ancestor-or-self::CMD"))
    8181    else
    82       for $coll in $collections return util:eval(fn:concat("$collection", $sanitized-query, "/ancestor-or-self::CMD[descendant::IsPartOf = '", xdb:decode($coll) ,"']"))
     82      for $coll in $collections return util:eval(fn:concat("$collection/ft:query(descendant::IsPartOf, <term>", xdb:decode($coll) ,"</term>)/ancestor-or-self::CMD[", $sanitized-query, "]"))
    8383
    8484    let $result-count := fn:count($results),
     
    8989    <searchRetrieveResponse>
    9090      <numberOfRecords>{$result-count}</numberOfRecords>
    91       <echoedSearchRetrieveRequest>{if ($decoded-query ne $sanitized-query) then "Rewritten to descendant-or-self::CMD" else $xpath-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest>
     91      <echoedSearchRetrieveRequest>{if ($decoded-query ne $sanitized-query) then concat("Rewritten to ", $sanitized-query) else $xpath-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest>
    9292      <extraResponseData>
    93                 <returnedRecords>{$seq-count}</returnedRecords>
    94                 <duration>{$end-time - $start-time}</duration>
     93        <returnedRecords>{$seq-count}</returnedRecords>
     94        <duration>{$end-time - $start-time}</duration>
    9595      </extraResponseData>
    9696      <records>
     
    110110
    111111declare function cmd-model:sanitize-query($query as xs:string) as xs:string {
    112 if ($query = ("//*", "descendant::element()")) then "/descendant-or-self::CMD" else $query
     112let $last-segment := text:groups($query, "/([^/]+)$")[last()]
     113return
     114  if ($query = ("//*", "descendant::element()")) then
     115    "/descendant-or-self::CMD"
     116  else if ($last-segment = ("Title", "Name", "Role", "Genre", "Country", "Continent", "MdSelfLink", "IsPartOf")) then
     117    (: concat("ft:query(",:) if ($query eq concat("//", $last-segment)) then concat("descendant::", $last-segment) else $query (:, ", <regex>.*</regex>)") :)
     118  else $query
    113119};
    114120
Note: See TracChangeset for help on using the changeset viewer.