Skip to content

Instantly share code, notes, and snippets.

@dstuebe
Last active December 10, 2015 13:08
Show Gist options
  • Save dstuebe/4438473 to your computer and use it in GitHub Desktop.
Save dstuebe/4438473 to your computer and use it in GitHub Desktop.
Query Info from the basex gui using full text and geospatial query
Query: declare namespace gmd="http://www.isotc211.org/2005/gmd"; declare namespace gco="http://www.isotc211.org/2005/gco"; declare namespace gmi="http://www.isotc211.org/2005/gmi"; declare namespace gml="http://www.opengis.net/gml"; declare namespace xs="http://www.w3.org/2001/XMLSchema"; declare function local:FreeTextQueryFunction($sequences, $textsearch) { let $searchTerms := tokenize($textsearch,'\s+') for $val in $sequences where ($val//text() contains text {$searchTerms} all using fuzzy ) return$val }; declare function local:GeoSpatialWithinQueryFunction($sequences, $west, $east, $north, $south) { for $val in $sequences let $bbox := $val//gmd:EX_GeographicBoundingBox let $westB := $bbox/gmd:westBoundLongitude/gco:Decimal let $eastB := $bbox/gmd:eastBoundLongitude/gco:Decimal let $southB := $bbox/gmd:southBoundLatitude/gco:Decimal let $northB := $bbox/gmd:northBoundLatitude/gco:Decimal where ($west <= $westB and $east >= $eastB and $south <= $southB and $north >= $northB) return $val }; declare function local:TemporalIntersectsQueryFunction($sequences, $startQ, $endQ) { for $val in $sequences let $bbox := $val//gml:TimePeriod let $startB := $bbox/gml:beginPosition let $endB := $bbox/gml:endPosition let $now := adjust-dateTime-to-timezone(current-dateTime(),xs:dayTimeDuration("PT0H")) let $endB := if($endB/@indeterminatePosition = "now") then $now else $endB let $startB := if($startB/@indeterminatePosition = "now") then $now else $startB where ( $startB != "" and $startQ <= $startB and $startB <= $endQ or $endB != "" and $endQ >= $endB and $endB >= $startQ or $startB != "" and $startB <= $startQ and $startQ <= $endB or $endB != "" and $endB >= $endQ and $endQ >= $startB ) return $val }; declare function local:GeoSpatialIntersectsQueryFunction($sequences, $westQ, $eastQ, $northQ, $southQ) { for $val in $sequences let $bbox := $val//gmd:EX_GeographicBoundingBox let $westB := $bbox/gmd:westBoundLongitude/gco:Decimal let $eastB := $bbox/gmd:eastBoundLongitude/gco:Decimal let $southB := $bbox/gmd:southBoundLatitude/gco:Decimal let $northB := $bbox/gmd:northBoundLatitude/gco:Decimal where ( ($eastQ >= $westB and $westB >= $westQ or $westQ <= $eastB and $eastB <= $eastQ or $eastB >= $westQ and $westQ >= $westB or $westB <= $eastQ and $eastQ <= $eastB) and ($northQ >= $northB and $northB >= $southQ or $southQ <= $southB and $southB <= $northQ or $northB >= $northQ and $northQ >= $southB or $southB <= $southQ and $southQ <= $northB) ) return $val }; declare function local:OrderByFunction($sequences) { for $val in $sequences let $title := $val//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString/text() order by $title return $val }; declare function local:FormatResult($fois) { for $foi in $fois return <gmd:MD_Metadata> {$foi/gmd:fileIdentifier} {$foi/gmd:identificationInfo} {$foi/gmd:distributionInfo} {$foi/gmd:contentInfo} </gmd:MD_Metadata> }; declare variable $records as xs:integer external := 20; declare variable $start as xs:integer external := 1; declare variable $textSearch as xs:boolean external := true(); declare variable $searchTerm as xs:string external := "temperature water"; declare variable $geoSearch as xs:boolean external := false(); declare variable $west as xs:decimal external := -86.0; declare variable $east as xs:decimal external := -71.9; declare variable $north as xs:decimal external := 46.; declare variable $south as xs:decimal external := 43.; declare variable $temporalSearch as xs:boolean external := false(); declare variable $tstart as xs:string external := "2011-05-22T23:59:00"; declare variable $tend as xs:string external := "2011-05-23T00:01:00"; let $resultSequence := /* let $resultSequence := if ($textSearch) then local:FreeTextQueryFunction($resultSequence, $searchTerm) else $resultSequence let $resultSequence := if ($geoSearch) then local:GeoSpatialIntersectsQueryFunction($resultSequence, $west, $east, $north, $south) else $resultSequence let $resultSequence := if ($temporalSearch) then local:TemporalIntersectsQueryFunction($resultSequence, $tstart, $tend) else $resultSequence let $resultSequence := if (not ($textSearch)) then local:OrderByFunction($resultSequence) else $resultSequence let $max := count($resultSequence) let $end := min (($start + $records - 1, $max)) let $num := min (($max, $records)) return <csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.2" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd"> <csw:RequestId/> <csw:SearchStatus timestamp="{current-dateTime()}"/> <csw:SearchResults nextRecord="{$end + 1}" numberOfRecordsMatched="{$max}" numberOfRecordsReturned="{$num}" recordSchema="http://www.isotc211.org/2005/gmd"> {local:FormatResult(subsequence($resultSequence, $start, $records))} </csw:SearchResults> </csw:GetRecordsResponse>
Compiling:
- rewriting where clause to predicate(s)
- simplifying descendant-or-self step(s)
- simplifying descendant-or-self step(s)
- pre-evaluating fn:current-dateTime()
- pre-evaluating "PT0H" cast as xs:dayTimeDuration
- pre-evaluating fn:adjust-dateTime-to-timezone("2013-01-02T16:47:18.167-05:00", "PT0S")
- binding static variable $now
- removing variable $now
- moving for/let clauses
- simplifying descendant-or-self step(s)
- moving for/let clauses
- simplifying descendant-or-self step(s)
- pre-evaluating fn:true()
- pre-evaluating if(true()) then local:FreeTextQueryFunction($resultSequence, "temperature water") else $resultSequence
- pre-evaluating fn:false()
- pre-evaluating if(false()) then local:GeoSpatialIntersectsQueryFunction($resultSequence, $west, $east, $north, $south) else $resultSequence
- pre-evaluating fn:false()
- pre-evaluating if(false()) then local:TemporalIntersectsQueryFunction($resultSequence, $tstart, $tend) else $resultSequence
- pre-evaluating fn:not(true())
- pre-evaluating if(false()) then local:OrderByFunction($resultSequence) else $resultSequence
- pre-evaluating 1 + 20
- pre-evaluating 21 - 1
- pre-evaluating fn:current-dateTime()
- moving for/let clauses
Result: declare function local:FreeTextQueryFunction($sequences, $textsearch) { let $searchTerms := fn:tokenize($textsearch, "\s+") for $val in ($sequences)[descendant::text() contains text { $searchTerms } all] return $val }; declare function local:GeoSpatialWithinQueryFunction($sequences, $west, $east, $north, $south) { for $val in $sequences let $bbox := $val/descendant-or-self::node()/gmd:EX_GeographicBoundingBox let $westB := $bbox/gmd:westBoundLongitude/gco:Decimal let $eastB := $bbox/gmd:eastBoundLongitude/gco:Decimal let $southB := $bbox/gmd:southBoundLatitude/gco:Decimal let $northB := $bbox/gmd:northBoundLatitude/gco:Decimal where $west <= $westB and $east >= $eastB and $south <= $southB and $north >= $northB return $val }; declare function local:TemporalIntersectsQueryFunction($sequences, $startQ, $endQ) { for $val in $sequences let $bbox := $val/descendant::gml:TimePeriod let $endB := $bbox/gml:endPosition let $endB := if($endB/@indeterminatePosition = "now") then "2013-01-02T21:47:18.167Z" else $endB let $startB := $bbox/gml:beginPosition let $startB := if($startB/@indeterminatePosition = "now") then "2013-01-02T21:47:18.167Z" else $startB where $startB != "" and $startQ <= $startB and $startB <= $endQ or $endB != "" and $endQ >= $endB and $endB >= $startQ or $startB != "" and $startB <= $startQ and $startQ <= $endB or $endB != "" and $endB >= $endQ and $endQ >= $startB return $val }; declare function local:GeoSpatialIntersectsQueryFunction($sequences, $westQ, $eastQ, $northQ, $southQ) { for $val in $sequences let $bbox := $val/descendant::gmd:EX_GeographicBoundingBox let $northB := $bbox/gmd:northBoundLatitude/gco:Decimal let $southB := $bbox/gmd:southBoundLatitude/gco:Decimal let $eastB := $bbox/gmd:eastBoundLongitude/gco:Decimal let $westB := $bbox/gmd:westBoundLongitude/gco:Decimal where $eastQ >= $westB and $westB >= $westQ or $westQ <= $eastB and $eastB <= $eastQ or $eastB >= $westQ and $westQ >= $westB or $westB <= $eastQ and $eastQ <= $eastB and $northQ >= $northB and $northB >= $southQ or $southQ <= $southB and $southB <= $northQ or $northB >= $northQ and $northQ >= $southB or $southB <= $southQ and $southQ <= $northB return $val }; declare function local:OrderByFunction($sequences) { for $val in $sequences let $title := $val/descendant::gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString/text() order by $title return $val }; declare function local:FormatResult($fois) { for $foi in $fois return element { "gmd:MD_Metadata" } { $foi/gmd:fileIdentifier, $foi/gmd:identificationInfo, $foi/gmd:distributionInfo, $foi/gmd:contentInfo } }; let $resultSequence := (document-node { "GeoNetwork/00f8abf6-cf6d-4f71-b9d0-b75ff5c2a672/metadata/metadata.xml" }, ...)/* let $resultSequence := local:FreeTextQueryFunction($resultSequence, "temperature water") let $resultSequence := $resultSequence let $resultSequence := $resultSequence let $resultSequence := $resultSequence let $max := fn:count($resultSequence) let $num := fn:min(($max, 20)) let $end := fn:min((20, $max)) return element { "csw:GetRecordsResponse" } { attribute { "version" } { "2.0.2" }, attribute { "xsi:schemaLocation" } { "http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd" }, element { "csw:RequestId" } { () }, element { "csw:SearchStatus" } { attribute { "timestamp" } { "2013-01-02T16:47:18.167-05:00" } }, element { "csw:SearchResults" } { attribute { "nextRecord" } { $end + 1 }, attribute { "numberOfRecordsMatched" } { $max }, attribute { "numberOfRecordsReturned" } { $num }, attribute { "recordSchema" } { "http://www.isotc211.org/2005/gmd" }, local:FormatResult(fn:subsequence($resultSequence, 1, 20)) } }
Timing:
- Parsing: 3.69 ms
- Compiling: 2.5 ms
- Evaluating: 917.09 ms
- Printing: 10.32 ms
- Total Time: 933.62 ms
Result:
- Hit(s): 1 Item
- Updated: 0 Items
- Printed: 351 KB
Query plan:
<QueryPlan>
<UserFuncs>
<UserFunc name="local:FreeTextQueryFunction" arg0="sequences" arg1="textsearch">
<FLWR>
<Let var="$searchTerms">
<FNPat name="tokenize(item,pattern[,mod])">
<VarRef>
<Var name="$textsearch" id="1"/>
</VarRef>
<Str value="\s+" type="xs:string"/>
</FNPat>
</Let>
<For var="$val">
<IterFilter>
<VarRef>
<Var name="$sequences" id="0"/>
</VarRef>
<FTContains>
<AxisPath>
<IterStep axis="descendant" test="text()"/>
</AxisPath>
<FTWords>
<VarRef>
<Var name="$searchTerms" id="2"/>
</VarRef>
</FTWords>
</FTContains>
</IterFilter>
</For>
<Return>
<VarRef>
<Var name="$val" id="3"/>
</VarRef>
</Return>
</FLWR>
</UserFunc>
<UserFunc name="local:GeoSpatialWithinQueryFunction" arg0="sequences" arg1="west" arg2="east" arg3="north" arg4="south">
<FLWR>
<For var="$val">
<VarRef>
<Var name="$sequences" id="4"/>
</VarRef>
</For>
<Let var="$bbox">
<AxisPath>
<VarRef>
<Var name="$val" id="9"/>
</VarRef>
<IterStep axis="descendant-or-self" test="node()"/>
<IterStep axis="child" test="gmd:EX_GeographicBoundingBox"/>
</AxisPath>
</Let>
<Let var="$westB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="10"/>
</VarRef>
<IterStep axis="child" test="gmd:westBoundLongitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Let var="$eastB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="10"/>
</VarRef>
<IterStep axis="child" test="gmd:eastBoundLongitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Let var="$southB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="10"/>
</VarRef>
<IterStep axis="child" test="gmd:southBoundLatitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Let var="$northB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="10"/>
</VarRef>
<IterStep axis="child" test="gmd:northBoundLatitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Where>
<And>
<CmpG op="&lt;=">
<VarRef>
<Var name="$west" id="5"/>
</VarRef>
<VarRef>
<Var name="$westB" id="11"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$east" id="6"/>
</VarRef>
<VarRef>
<Var name="$eastB" id="12"/>
</VarRef>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$south" id="8"/>
</VarRef>
<VarRef>
<Var name="$southB" id="13"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$north" id="7"/>
</VarRef>
<VarRef>
<Var name="$northB" id="14"/>
</VarRef>
</CmpG>
</And>
</Where>
<Return>
<VarRef>
<Var name="$val" id="9"/>
</VarRef>
</Return>
</FLWR>
</UserFunc>
<UserFunc name="local:TemporalIntersectsQueryFunction" arg0="sequences" arg1="startQ" arg2="endQ">
<FLWR>
<For var="$val">
<VarRef>
<Var name="$sequences" id="15"/>
</VarRef>
</For>
<Let var="$bbox">
<AxisPath>
<VarRef>
<Var name="$val" id="18"/>
</VarRef>
<IterStep axis="descendant" test="gml:TimePeriod"/>
</AxisPath>
</Let>
<Let var="$endB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="19"/>
</VarRef>
<IterStep axis="child" test="gml:endPosition"/>
</AxisPath>
</Let>
<Let var="$endB">
<If>
<CmpG op="=">
<AxisPath>
<VarRef>
<Var name="$endB" id="21"/>
</VarRef>
<IterStep axis="attribute" test="indeterminatePosition"/>
</AxisPath>
<Str value="now" type="xs:string"/>
</CmpG>
<Dtm value="2013-01-02T21:47:18.167Z" type="xs:dateTime"/>
<VarRef>
<Var name="$endB" id="21"/>
</VarRef>
</If>
</Let>
<Let var="$startB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="19"/>
</VarRef>
<IterStep axis="child" test="gml:beginPosition"/>
</AxisPath>
</Let>
<Let var="$startB">
<If>
<CmpG op="=">
<AxisPath>
<VarRef>
<Var name="$startB" id="20"/>
</VarRef>
<IterStep axis="attribute" test="indeterminatePosition"/>
</AxisPath>
<Str value="now" type="xs:string"/>
</CmpG>
<Dtm value="2013-01-02T21:47:18.167Z" type="xs:dateTime"/>
<VarRef>
<Var name="$startB" id="20"/>
</VarRef>
</If>
</Let>
<Where>
<Or>
<And>
<CmpG op="!=">
<VarRef>
<Var name="$startB" id="24"/>
</VarRef>
<Str value="" type="xs:string"/>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$startQ" id="16"/>
</VarRef>
<VarRef>
<Var name="$startB" id="24"/>
</VarRef>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$startB" id="24"/>
</VarRef>
<VarRef>
<Var name="$endQ" id="17"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="!=">
<VarRef>
<Var name="$endB" id="23"/>
</VarRef>
<Str value="" type="xs:string"/>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$endQ" id="17"/>
</VarRef>
<VarRef>
<Var name="$endB" id="23"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$endB" id="23"/>
</VarRef>
<VarRef>
<Var name="$startQ" id="16"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="!=">
<VarRef>
<Var name="$startB" id="24"/>
</VarRef>
<Str value="" type="xs:string"/>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$startB" id="24"/>
</VarRef>
<VarRef>
<Var name="$startQ" id="16"/>
</VarRef>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$startQ" id="16"/>
</VarRef>
<VarRef>
<Var name="$endB" id="23"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="!=">
<VarRef>
<Var name="$endB" id="23"/>
</VarRef>
<Str value="" type="xs:string"/>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$endB" id="23"/>
</VarRef>
<VarRef>
<Var name="$endQ" id="17"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$endQ" id="17"/>
</VarRef>
<VarRef>
<Var name="$startB" id="24"/>
</VarRef>
</CmpG>
</And>
</Or>
</Where>
<Return>
<VarRef>
<Var name="$val" id="18"/>
</VarRef>
</Return>
</FLWR>
</UserFunc>
<UserFunc name="local:GeoSpatialIntersectsQueryFunction" arg0="sequences" arg1="westQ" arg2="eastQ" arg3="northQ" arg4="southQ">
<FLWR>
<For var="$val">
<VarRef>
<Var name="$sequences" id="25"/>
</VarRef>
</For>
<Let var="$bbox">
<AxisPath>
<VarRef>
<Var name="$val" id="30"/>
</VarRef>
<IterStep axis="descendant" test="gmd:EX_GeographicBoundingBox"/>
</AxisPath>
</Let>
<Let var="$northB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="31"/>
</VarRef>
<IterStep axis="child" test="gmd:northBoundLatitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Let var="$southB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="31"/>
</VarRef>
<IterStep axis="child" test="gmd:southBoundLatitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Let var="$eastB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="31"/>
</VarRef>
<IterStep axis="child" test="gmd:eastBoundLongitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Let var="$westB">
<AxisPath>
<VarRef>
<Var name="$bbox" id="31"/>
</VarRef>
<IterStep axis="child" test="gmd:westBoundLongitude"/>
<IterStep axis="child" test="gco:Decimal"/>
</AxisPath>
</Let>
<Where>
<And>
<Or>
<And>
<CmpG op="&gt;=">
<VarRef>
<Var name="$eastQ" id="27"/>
</VarRef>
<VarRef>
<Var name="$westB" id="32"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$westB" id="32"/>
</VarRef>
<VarRef>
<Var name="$westQ" id="26"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="&lt;=">
<VarRef>
<Var name="$westQ" id="26"/>
</VarRef>
<VarRef>
<Var name="$eastB" id="33"/>
</VarRef>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$eastB" id="33"/>
</VarRef>
<VarRef>
<Var name="$eastQ" id="27"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="&gt;=">
<VarRef>
<Var name="$eastB" id="33"/>
</VarRef>
<VarRef>
<Var name="$westQ" id="26"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$westQ" id="26"/>
</VarRef>
<VarRef>
<Var name="$westB" id="32"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="&lt;=">
<VarRef>
<Var name="$westB" id="32"/>
</VarRef>
<VarRef>
<Var name="$eastQ" id="27"/>
</VarRef>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$eastQ" id="27"/>
</VarRef>
<VarRef>
<Var name="$eastB" id="33"/>
</VarRef>
</CmpG>
</And>
</Or>
<Or>
<And>
<CmpG op="&gt;=">
<VarRef>
<Var name="$northQ" id="28"/>
</VarRef>
<VarRef>
<Var name="$northB" id="35"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$northB" id="35"/>
</VarRef>
<VarRef>
<Var name="$southQ" id="29"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="&lt;=">
<VarRef>
<Var name="$southQ" id="29"/>
</VarRef>
<VarRef>
<Var name="$southB" id="34"/>
</VarRef>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$southB" id="34"/>
</VarRef>
<VarRef>
<Var name="$northQ" id="28"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="&gt;=">
<VarRef>
<Var name="$northB" id="35"/>
</VarRef>
<VarRef>
<Var name="$northQ" id="28"/>
</VarRef>
</CmpG>
<CmpG op="&gt;=">
<VarRef>
<Var name="$northQ" id="28"/>
</VarRef>
<VarRef>
<Var name="$southB" id="34"/>
</VarRef>
</CmpG>
</And>
<And>
<CmpG op="&lt;=">
<VarRef>
<Var name="$southB" id="34"/>
</VarRef>
<VarRef>
<Var name="$southQ" id="29"/>
</VarRef>
</CmpG>
<CmpG op="&lt;=">
<VarRef>
<Var name="$southQ" id="29"/>
</VarRef>
<VarRef>
<Var name="$northB" id="35"/>
</VarRef>
</CmpG>
</And>
</Or>
</And>
</Where>
<Return>
<VarRef>
<Var name="$val" id="30"/>
</VarRef>
</Return>
</FLWR>
</UserFunc>
<UserFunc name="local:OrderByFunction" arg0="sequences">
<GFLWOR>
<For var="$val">
<VarRef>
<Var name="$sequences" id="36"/>
</VarRef>
</For>
<Let var="$title">
<AxisPath>
<VarRef>
<Var name="$val" id="37"/>
</VarRef>
<IterStep axis="descendant" test="gmd:identificationInfo"/>
<IterStep axis="child" test="gmd:MD_DataIdentification"/>
<IterStep axis="child" test="gmd:citation"/>
<IterStep axis="child" test="gmd:CI_Citation"/>
<IterStep axis="child" test="gmd:title"/>
<IterStep axis="child" test="gco:CharacterString"/>
<IterStep axis="child" test="text()"/>
</AxisPath>
</Let>
<Order>
<OrderByExpr dir="ascending" empty="least">
<VarRef>
<Var name="$title" id="38"/>
</VarRef>
</OrderByExpr>
</Order>
<Return>
<VarRef>
<Var name="$val" id="37"/>
</VarRef>
</Return>
</GFLWOR>
</UserFunc>
<UserFunc name="local:FormatResult" arg0="fois">
<FLWR>
<For var="$foi">
<VarRef>
<Var name="$fois" id="39"/>
</VarRef>
</For>
<Return>
<CElem>
<QNm value="gmd:MD_Metadata" type="xs:QName"/>
<AxisPath>
<VarRef>
<Var name="$foi" id="40"/>
</VarRef>
<IterStep axis="child" test="gmd:fileIdentifier"/>
</AxisPath>
<AxisPath>
<VarRef>
<Var name="$foi" id="40"/>
</VarRef>
<IterStep axis="child" test="gmd:identificationInfo"/>
</AxisPath>
<AxisPath>
<VarRef>
<Var name="$foi" id="40"/>
</VarRef>
<IterStep axis="child" test="gmd:distributionInfo"/>
</AxisPath>
<AxisPath>
<VarRef>
<Var name="$foi" id="40"/>
</VarRef>
<IterStep axis="child" test="gmd:contentInfo"/>
</AxisPath>
</CElem>
</Return>
</FLWR>
</UserFunc>
</UserFuncs>
<VarStack>
<Var name="$records as xs:integer" id="41">
<Int value="20" type="xs:integer"/>
</Var>
<Var name="$start as xs:integer" id="42">
<Int value="1" type="xs:integer"/>
</Var>
<Var name="$textSearch as xs:boolean" id="43">
<FNSimple name="true()"/>
</Var>
<Var name="$searchTerm as xs:string" id="44">
<Str value="temperature water" type="xs:string"/>
</Var>
<Var name="$geoSearch as xs:boolean" id="45">
<FNSimple name="false()"/>
</Var>
<Var name="$west as xs:decimal" id="46">
<Unary value="true">
<Dec value="86" type="xs:decimal"/>
</Unary>
</Var>
<Var name="$east as xs:decimal" id="47">
<Unary value="true">
<Dec value="71.9" type="xs:decimal"/>
</Unary>
</Var>
<Var name="$north as xs:decimal" id="48">
<Dec value="46" type="xs:decimal"/>
</Var>
<Var name="$south as xs:decimal" id="49">
<Dec value="43" type="xs:decimal"/>
</Var>
<Var name="$temporalSearch as xs:boolean" id="50">
<FNSimple name="false()"/>
</Var>
<Var name="$tstart as xs:string" id="51">
<Str value="2011-05-22T23:59:00" type="xs:string"/>
</Var>
<Var name="$tend as xs:string" id="52">
<Str value="2011-05-23T00:01:00" type="xs:string"/>
</Var>
</VarStack>
<FLWR>
<Let var="$resultSequence">
<IterPath>
<DBNodeSeq size="5396">
<DBNode name="ISOs" pre="0"/>
<DBNode name="ISOs" pre="249"/>
<DBNode name="ISOs" pre="475"/>
<DBNode name="ISOs" pre="724"/>
<DBNode name="ISOs" pre="966"/>
</DBNodeSeq>
<IterStep axis="child" test="*"/>
</IterPath>
</Let>
<Let var="$resultSequence">
<BaseFuncCall name="local:FreeTextQueryFunction($resultSequence, &quot;temperature water&quot;)">
<VarRef>
<Var name="$resultSequence" id="53"/>
</VarRef>
<Str value="temperature water" type="xs:string"/>
</BaseFuncCall>
</Let>
<Let var="$resultSequence">
<VarRef>
<Var name="$resultSequence" id="54"/>
</VarRef>
</Let>
<Let var="$resultSequence">
<VarRef>
<Var name="$resultSequence" id="55"/>
</VarRef>
</Let>
<Let var="$resultSequence">
<VarRef>
<Var name="$resultSequence" id="56"/>
</VarRef>
</Let>
<Let var="$max">
<FNAggr name="count(item)">
<VarRef>
<Var name="$resultSequence" id="57"/>
</VarRef>
</FNAggr>
</Let>
<Let var="$num">
<FNAggr name="min(item[,coll])">
<List>
<VarRef>
<Var name="$max" id="58"/>
</VarRef>
<Int value="20" type="xs:integer"/>
</List>
</FNAggr>
</Let>
<Let var="$end">
<FNAggr name="min(item[,coll])">
<List>
<Int value="20" type="xs:integer"/>
<VarRef>
<Var name="$max" id="58"/>
</VarRef>
</List>
</FNAggr>
</Let>
<Return>
<CElem>
<QNm value="csw:GetRecordsResponse" type="xs:QName"/>
<CAttr>
<QNm value="version" type="xs:QName"/>
<Str value="2.0.2" type="xs:string"/>
</CAttr>
<CAttr>
<QNm value="xsi:schemaLocation" type="xs:QName"/>
<Str value="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd" type="xs:string"/>
</CAttr>
<CElem>
<QNm value="csw:RequestId" type="xs:QName"/>
</CElem>
<CElem>
<QNm value="csw:SearchStatus" type="xs:QName"/>
<CAttr>
<QNm value="timestamp" type="xs:QName"/>
<Dtm value="2013-01-02T16:47:18.167-05:00" type="xs:dateTime"/>
</CAttr>
</CElem>
<CElem>
<QNm value="csw:SearchResults" type="xs:QName"/>
<CAttr>
<QNm value="nextRecord" type="xs:QName"/>
<Arith op="+">
<VarRef>
<Var name="$end" id="59"/>
</VarRef>
<Int value="1" type="xs:integer"/>
</Arith>
</CAttr>
<CAttr>
<QNm value="numberOfRecordsMatched" type="xs:QName"/>
<VarRef>
<Var name="$max" id="58"/>
</VarRef>
</CAttr>
<CAttr>
<QNm value="numberOfRecordsReturned" type="xs:QName"/>
<VarRef>
<Var name="$num" id="60"/>
</VarRef>
</CAttr>
<CAttr>
<QNm value="recordSchema" type="xs:QName"/>
<Str value="http://www.isotc211.org/2005/gmd" type="xs:string"/>
</CAttr>
<BaseFuncCall name="local:FormatResult(fn:subsequence($resultSequence, 1, 20))">
<FNSeq name="subsequence(items,start[,len])">
<VarRef>
<Var name="$resultSequence" id="57"/>
</VarRef>
<Int value="1" type="xs:integer"/>
<Int value="20" type="xs:integer"/>
</FNSeq>
</BaseFuncCall>
</CElem>
</CElem>
</Return>
</FLWR>
</QueryPlan>
Query: for $val in /* where ($val//text() contains text {('water', 'temperature')} all using fuzzy ) return$val
Compiling:
- rewriting where clause to predicate(s)
- simplifying descendant-or-self step(s)
- pre-evaluating ("water", "temperature")
- applying full-text index
- simplifying flwor expression
Result: db:fulltext("ISOs", { ("water", "temperature") } all)/ancestor::*[parent::document-node()]
Timing:
- Parsing: 0.42 ms
- Compiling: 0.87 ms
- Evaluating: 79.83 ms
- Printing: 77.45 ms
- Total Time: 158.59 ms
Result:
- Hit(s): 1677 Items
- Updated: 0 Items
- Printed: 2048 KB
Query plan:
<QueryPlan>
<AxisPath>
<FTIndexAccess data="ISOs">
<FTWords>
<ItemSeq size="2">
<Str value="water" type="xs:string"/>
<Str value="temperature" type="xs:string"/>
</ItemSeq>
</FTWords>
</FTIndexAccess>
<IterStep axis="ancestor" test="*">
<AxisPath>
<IterStep axis="parent" test="document-node()"/>
</AxisPath>
</IterStep>
</AxisPath>
</QueryPlan>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment