Hello,
I wonder if the attached query can be optimised. I'm attaching all relevant information.
Basex 7.9, Debian, powerful server.
This is just an example. The queries will be built based on a compilation of a search form. So reordering the conditions for having smaller subset right from the begging isn't relevant.
Any help would be appreciated.
40 seconds are not acceptable.

--
With kind regards,
Menashè

Compiling:
- pre-evaluating fn:collection("ALL-CDIS")
- pre-evaluating ("ALKY", "AYMD")
- rewriting ((db:open-pre("ALL-CDIS",0), db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal
 >= "13.708333")
- rewriting ((db:open-pre("ALL-CDIS",0), db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:eastBoundLongitude/gco:Decimal
 <= "15.708333")
- rewriting ((db:open-pre("ALL-CDIS",0), db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:southBoundLatitude/gco:Decimal
 >= "45.6976667")
- rewriting ((db:open-pre("ALL-CDIS",0), db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal
 <= "55.6976667")
- pre-evaluating "2012-03-30T09:07:00" cast as xs:dateTime
- atomic evaluation of 
(fn:string($x_0/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition)
 cast as xs:dateTime >= "2012-03-30T09:07:00")
- pre-evaluating "2012-04-30T09:07:00" cast as xs:dateTime
- atomic evaluation of 
(fn:string($x_0/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition)
 cast as xs:dateTime <= "2012-04-30T09:07:00")
- removing context expression (.)
- removing context expression (.)
- atomic evaluation of 
(fn:string(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition)
 cast as xs:dateTime >= "2012-03-30T09:07:00")
- removing context expression (.)
- atomic evaluation of 
(fn:string(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition)
 cast as xs:dateTime <= "2012-04-30T09:07:00")
- removing context expression (.)
- removing context expression (.)
- removing context expression (.)
- removing context expression (.)
- removing context expression (.)
- rewriting where clause(s)
Query:
xquery version "3.0"; declare namespace gco = 
"http://www.isotc211.org/2005/gco";; declare namespace gmd = 
"http://www.isotc211.org/2005/gmd";; declare namespace gml = 
"http://www.opengis.net/gml";; declare namespace 
gmx="http://www.isotc211.org/2005/gmx";; declare namespace sdn = 
"http://www.seadatanet.org";; declare namespace fn = 
"http://www.w3.org/2005/xpath-functions";; declare namespace xs = 
"http://www.w3.org/2001/XMLSchema";; for $x in collection("ALL-CDIS") where 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword[*]/sdn:SDN_ParameterDiscoveryCode/@codeListValue
 = ("ALKY","AYMD") and 
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal
 >= "13.708333" and 
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:eastBoundLongitude/gco:Decimal
 <= "15.708333" and 
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:southBoundLatitude/gco:Decimal
 >= "45.6976667" and 
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal
 <= "55.6976667" and 
xs:dateTime(string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition))
 >= xs:dateTime("2012-03-30T09:07:00") and 
xs:dateTime(string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition))
 <= xs:dateTime("2012-04-30T09:07:00") and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword/sdn:SDN_DeviceCategoryCode/@codeListValue
 = 130 and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword/sdn:SDN_EDMERPCode/@codeListValue
 = 7827 and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty/gmd:organisationName/sdn:SDN_EDMOCode/@codeListValue
 = 120 and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty/gmd:role/gmd:CI_RoleCode/@codeListValue="originator"
 and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:resourceConstraints[*]/gmd:MD_LegalConstraints/gmd:otherConstraints/gmx:Anchor/text()
 = "unrestricted" order by 
string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:alternateTitle/gco:CharacterString)
 return 
string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:alternateTitle/gco:CharacterString)
Optimized Query:
if(((db:open-pre("ALL-CDIS",0), db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:eastBoundLongitude/gco:Decimal
 <= "15.708333" and "45.6976667" <= (db:open-pre("ALL-CDIS",0), 
db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:southBoundLatitude/gco:Decimal
 and (db:open-pre("ALL-CDIS",0), db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal
 <= "55.6976667" and "13.708333" <= (db:open-pre("ALL-CDIS",0), 
db:open-pre("ALL-CDIS",747), 
...)/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal))
 then for $x_0 in (db:open-pre("ALL-CDIS",0), db:open-pre("ALL-CDIS",747), 
...)[(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword[*]/sdn:SDN_ParameterDiscoveryCode/@codeListValue
 = ("ALKY", 
"AYMD"))][(fn:string(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition)
 cast as xs:dateTime >= 
"2012-03-30T09:07:00")][(fn:string(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition)
 cast as xs:dateTime <= 
"2012-04-30T09:07:00")][(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword/sdn:SDN_DeviceCategoryCode/@codeListValue
 = 
130)][(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword/sdn:SDN_EDMERPCode/@codeListValue
 = 
7827)][(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty/gmd:organisationName/sdn:SDN_EDMOCode/@codeListValue
 = 
120)][(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty/gmd:role/gmd:CI_RoleCode/@codeListValue
 = 
"originator")][(gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:resourceConstraints[*]/gmd:MD_LegalConstraints/gmd:otherConstraints/gmx:Anchor/text()
 = "unrestricted")] order by 
fn:string($x_0/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:alternateTitle/gco:CharacterString)
 empty least return 
fn:string($x_0/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:alternateTitle/gco:CharacterString)
 else ()
Result:
- Hit(s): 1 Item
- Updated: 0 Items
- Printed: 6 Bytes
- Read Locking: local [ALL-CDIS]
- Write Locking: none
Timing:
- Parsing: 1.6 ms
- Compiling: 3.97 ms
- Evaluating: 39518.62 ms
- Printing: 1.92 ms
- Total Time: 39526.11 ms
Query plan:
<QueryPlan>
  <If>
    <And>
      <CmpSR min="" max="15.708333">
        <IterPath>
          <DBNodeSeq size="374739">
            <DBNode name="ALL-CDIS" pre="0"/>
            <DBNode name="ALL-CDIS" pre="747"/>
            <DBNode name="ALL-CDIS" pre="1494"/>
            <DBNode name="ALL-CDIS" pre="2197"/>
            <DBNode name="ALL-CDIS" pre="2900"/>
          </DBNodeSeq>
          <IterStep axis="child" test="gmd:MD_Metadata"/>
          <IterStep axis="child" test="gmd:identificationInfo"/>
          <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
          <IterStep axis="child" test="gmd:extent"/>
          <IterStep axis="child" test="gmd:EX_Extent"/>
          <IterStep axis="child" test="gmd:geographicElement"/>
          <IterStep axis="child" test="gmd:EX_GeographicBoundingBox"/>
          <IterStep axis="child" test="gmd:eastBoundLongitude"/>
          <IterStep axis="child" test="gco:Decimal"/>
        </IterPath>
      </CmpSR>
      <CmpSR min="45.6976667" max="">
        <IterPath>
          <DBNodeSeq size="374739">
            <DBNode name="ALL-CDIS" pre="0"/>
            <DBNode name="ALL-CDIS" pre="747"/>
            <DBNode name="ALL-CDIS" pre="1494"/>
            <DBNode name="ALL-CDIS" pre="2197"/>
            <DBNode name="ALL-CDIS" pre="2900"/>
          </DBNodeSeq>
          <IterStep axis="child" test="gmd:MD_Metadata"/>
          <IterStep axis="child" test="gmd:identificationInfo"/>
          <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
          <IterStep axis="child" test="gmd:extent"/>
          <IterStep axis="child" test="gmd:EX_Extent"/>
          <IterStep axis="child" test="gmd:geographicElement"/>
          <IterStep axis="child" test="gmd:EX_GeographicBoundingBox"/>
          <IterStep axis="child" test="gmd:southBoundLatitude"/>
          <IterStep axis="child" test="gco:Decimal"/>
        </IterPath>
      </CmpSR>
      <CmpSR min="" max="55.6976667">
        <IterPath>
          <DBNodeSeq size="374739">
            <DBNode name="ALL-CDIS" pre="0"/>
            <DBNode name="ALL-CDIS" pre="747"/>
            <DBNode name="ALL-CDIS" pre="1494"/>
            <DBNode name="ALL-CDIS" pre="2197"/>
            <DBNode name="ALL-CDIS" pre="2900"/>
          </DBNodeSeq>
          <IterStep axis="child" test="gmd:MD_Metadata"/>
          <IterStep axis="child" test="gmd:identificationInfo"/>
          <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
          <IterStep axis="child" test="gmd:extent"/>
          <IterStep axis="child" test="gmd:EX_Extent"/>
          <IterStep axis="child" test="gmd:geographicElement"/>
          <IterStep axis="child" test="gmd:EX_GeographicBoundingBox"/>
          <IterStep axis="child" test="gmd:northBoundLatitude"/>
          <IterStep axis="child" test="gco:Decimal"/>
        </IterPath>
      </CmpSR>
      <CmpSR min="13.708333" max="">
        <IterPath>
          <DBNodeSeq size="374739">
            <DBNode name="ALL-CDIS" pre="0"/>
            <DBNode name="ALL-CDIS" pre="747"/>
            <DBNode name="ALL-CDIS" pre="1494"/>
            <DBNode name="ALL-CDIS" pre="2197"/>
            <DBNode name="ALL-CDIS" pre="2900"/>
          </DBNodeSeq>
          <IterStep axis="child" test="gmd:MD_Metadata"/>
          <IterStep axis="child" test="gmd:identificationInfo"/>
          <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
          <IterStep axis="child" test="gmd:extent"/>
          <IterStep axis="child" test="gmd:EX_Extent"/>
          <IterStep axis="child" test="gmd:geographicElement"/>
          <IterStep axis="child" test="gmd:EX_GeographicBoundingBox"/>
          <IterStep axis="child" test="gmd:westBoundLongitude"/>
          <IterStep axis="child" test="gco:Decimal"/>
        </IterPath>
      </CmpSR>
    </And>
    <GFLWOR>
      <For>
        <Var name="$x" id="0"/>
        <CachedFilter>
          <DBNodeSeq size="374739">
            <DBNode name="ALL-CDIS" pre="0"/>
            <DBNode name="ALL-CDIS" pre="747"/>
            <DBNode name="ALL-CDIS" pre="1494"/>
            <DBNode name="ALL-CDIS" pre="2197"/>
            <DBNode name="ALL-CDIS" pre="2900"/>
          </DBNodeSeq>
          <CmpG op="=">
            <IterPath>
              <IterStep axis="child" test="gmd:MD_Metadata"/>
              <IterStep axis="child" test="gmd:identificationInfo"/>
              <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
              <IterStep axis="child" test="gmd:descriptiveKeywords">
                <CachedPath>
                  <IterStep axis="child" test="*"/>
                </CachedPath>
              </IterStep>
              <IterStep axis="child" test="gmd:MD_Keywords"/>
              <IterStep axis="child" test="gmd:keyword">
                <CachedPath>
                  <IterStep axis="child" test="*"/>
                </CachedPath>
              </IterStep>
              <IterStep axis="child" test="sdn:SDN_ParameterDiscoveryCode"/>
              <IterStep axis="attribute" test="codeListValue"/>
            </IterPath>
            <StrSeq size="2">
              <Str value="ALKY" type="xs:string"/>
              <Str value="AYMD" type="xs:string"/>
            </StrSeq>
          </CmpG>
          <CmpG op="&gt;=">
            <Cast type="xs:dateTime">
              <FNAcc name="string([item])">
                <IterPath>
                  <IterStep axis="child" test="gmd:MD_Metadata"/>
                  <IterStep axis="child" test="gmd:identificationInfo"/>
                  <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
                  <IterStep axis="child" test="gmd:extent"/>
                  <IterStep axis="child" test="gmd:EX_Extent"/>
                  <IterStep axis="child" test="gmd:temporalElement"/>
                  <IterStep axis="child" test="gmd:EX_TemporalExtent"/>
                  <IterStep axis="child" test="gmd:extent"/>
                  <IterStep axis="child" test="gml:TimePeriod"/>
                  <IterStep axis="child" test="gml:beginPosition"/>
                </IterPath>
              </FNAcc>
            </Cast>
            <Dtm value="2012-03-30T09:07:00" type="xs:dateTime"/>
          </CmpG>
          <CmpG op="&lt;=">
            <Cast type="xs:dateTime">
              <FNAcc name="string([item])">
                <IterPath>
                  <IterStep axis="child" test="gmd:MD_Metadata"/>
                  <IterStep axis="child" test="gmd:identificationInfo"/>
                  <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
                  <IterStep axis="child" test="gmd:extent"/>
                  <IterStep axis="child" test="gmd:EX_Extent"/>
                  <IterStep axis="child" test="gmd:temporalElement"/>
                  <IterStep axis="child" test="gmd:EX_TemporalExtent"/>
                  <IterStep axis="child" test="gmd:extent"/>
                  <IterStep axis="child" test="gml:TimePeriod"/>
                  <IterStep axis="child" test="gml:beginPosition"/>
                </IterPath>
              </FNAcc>
            </Cast>
            <Dtm value="2012-04-30T09:07:00" type="xs:dateTime"/>
          </CmpG>
          <CmpG op="=">
            <IterPath>
              <IterStep axis="child" test="gmd:MD_Metadata"/>
              <IterStep axis="child" test="gmd:identificationInfo"/>
              <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
              <IterStep axis="child" test="gmd:descriptiveKeywords">
                <CachedPath>
                  <IterStep axis="child" test="*"/>
                </CachedPath>
              </IterStep>
              <IterStep axis="child" test="gmd:MD_Keywords"/>
              <IterStep axis="child" test="gmd:keyword"/>
              <IterStep axis="child" test="sdn:SDN_DeviceCategoryCode"/>
              <IterStep axis="attribute" test="codeListValue"/>
            </IterPath>
            <Int value="130" type="xs:integer"/>
          </CmpG>
          <CmpG op="=">
            <IterPath>
              <IterStep axis="child" test="gmd:MD_Metadata"/>
              <IterStep axis="child" test="gmd:identificationInfo"/>
              <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
              <IterStep axis="child" test="gmd:descriptiveKeywords">
                <CachedPath>
                  <IterStep axis="child" test="*"/>
                </CachedPath>
              </IterStep>
              <IterStep axis="child" test="gmd:MD_Keywords"/>
              <IterStep axis="child" test="gmd:keyword"/>
              <IterStep axis="child" test="sdn:SDN_EDMERPCode"/>
              <IterStep axis="attribute" test="codeListValue"/>
            </IterPath>
            <Int value="7827" type="xs:integer"/>
          </CmpG>
          <CmpG op="=">
            <IterPath>
              <IterStep axis="child" test="gmd:MD_Metadata"/>
              <IterStep axis="child" test="gmd:identificationInfo"/>
              <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
              <IterStep axis="child" test="gmd:citation"/>
              <IterStep axis="child" test="gmd:CI_Citation"/>
              <IterStep axis="child" test="gmd:citedResponsibleParty"/>
              <IterStep axis="child" test="gmd:CI_ResponsibleParty"/>
              <IterStep axis="child" test="gmd:organisationName"/>
              <IterStep axis="child" test="sdn:SDN_EDMOCode"/>
              <IterStep axis="attribute" test="codeListValue"/>
            </IterPath>
            <Int value="120" type="xs:integer"/>
          </CmpG>
          <CmpG op="=">
            <IterPath>
              <IterStep axis="child" test="gmd:MD_Metadata"/>
              <IterStep axis="child" test="gmd:identificationInfo"/>
              <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
              <IterStep axis="child" test="gmd:citation"/>
              <IterStep axis="child" test="gmd:CI_Citation"/>
              <IterStep axis="child" test="gmd:citedResponsibleParty"/>
              <IterStep axis="child" test="gmd:CI_ResponsibleParty"/>
              <IterStep axis="child" test="gmd:role"/>
              <IterStep axis="child" test="gmd:CI_RoleCode"/>
              <IterStep axis="attribute" test="codeListValue"/>
            </IterPath>
            <Str value="originator" type="xs:string"/>
          </CmpG>
          <CmpG op="=">
            <IterPath>
              <IterStep axis="child" test="gmd:MD_Metadata"/>
              <IterStep axis="child" test="gmd:identificationInfo"/>
              <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
              <IterStep axis="child" test="gmd:resourceConstraints">
                <CachedPath>
                  <IterStep axis="child" test="*"/>
                </CachedPath>
              </IterStep>
              <IterStep axis="child" test="gmd:MD_LegalConstraints"/>
              <IterStep axis="child" test="gmd:otherConstraints"/>
              <IterStep axis="child" test="gmx:Anchor"/>
              <IterStep axis="child" test="text()"/>
            </IterPath>
            <Str value="unrestricted" type="xs:string"/>
          </CmpG>
        </CachedFilter>
      </For>
      <OrderBy>
        <Key dir="ascending" empty="least">
          <FNAcc name="string([item])">
            <IterPath>
              <VarRef>
                <Var name="$x" id="0"/>
              </VarRef>
              <IterStep axis="child" test="gmd:MD_Metadata"/>
              <IterStep axis="child" test="gmd:identificationInfo"/>
              <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
              <IterStep axis="child" test="gmd:citation"/>
              <IterStep axis="child" test="gmd:CI_Citation"/>
              <IterStep axis="child" test="gmd:alternateTitle"/>
              <IterStep axis="child" test="gco:CharacterString"/>
            </IterPath>
          </FNAcc>
        </Key>
      </OrderBy>
      <FNAcc name="string([item])">
        <IterPath>
          <VarRef>
            <Var name="$x" id="0"/>
          </VarRef>
          <IterStep axis="child" test="gmd:MD_Metadata"/>
          <IterStep axis="child" test="gmd:identificationInfo"/>
          <IterStep axis="child" test="sdn:SDN_DataIdentification"/>
          <IterStep axis="child" test="gmd:citation"/>
          <IterStep axis="child" test="gmd:CI_Citation"/>
          <IterStep axis="child" test="gmd:alternateTitle"/>
          <IterStep axis="child" test="gco:CharacterString"/>
        </IterPath>
      </FNAcc>
    </GFLWOR>
    <Empty size="0"/>
  </If>
</QueryPlan>

xquery version "3.0";
declare namespace gco = "http://www.isotc211.org/2005/gco";;
declare namespace gmd = "http://www.isotc211.org/2005/gmd";;
declare namespace gml = "http://www.opengis.net/gml";;
declare namespace gmx="http://www.isotc211.org/2005/gmx";;
declare namespace sdn = "http://www.seadatanet.org";;

declare namespace fn = "http://www.w3.org/2005/xpath-functions";;
declare namespace xs = "http://www.w3.org/2001/XMLSchema";;

for $x in collection("ALL-CDIS")
where 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword[*]/sdn:SDN_ParameterDiscoveryCode/@codeListValue
 = ("ALKY","AYMD")
and
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal
 >= "13.708333"
and
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:eastBoundLongitude/gco:Decimal
 <= "15.708333"
and
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:southBoundLatitude/gco:Decimal
 >= "45.6976667"
and
/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal
 <= "55.6976667"
and 
xs:dateTime(string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition))
 >= xs:dateTime("2012-03-30T09:07:00")
and 
xs:dateTime(string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition))
 <= xs:dateTime("2012-04-30T09:07:00")
and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword/sdn:SDN_DeviceCategoryCode/@codeListValue
 = 130
and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:descriptiveKeywords[*]/gmd:MD_Keywords/gmd:keyword/sdn:SDN_EDMERPCode/@codeListValue
 = 7827
        and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty/gmd:organisationName/sdn:SDN_EDMOCode/@codeListValue
 = 120
        and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty/gmd:role/gmd:CI_RoleCode/@codeListValue="originator"
and 
$x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:resourceConstraints[*]/gmd:MD_LegalConstraints/gmd:otherConstraints/gmx:Anchor/text()
 = "unrestricted"

order by 
string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:alternateTitle/gco:CharacterString)
return 
string($x/gmd:MD_Metadata/gmd:identificationInfo/sdn:SDN_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:alternateTitle/gco:CharacterString)
Database Properties
 Name: ALL-CDIS
 Size: 6749 MB
 Nodes: 272188514
 Documents: 374739
 Binaries: 0
 Timestamp: 2015-01-30-15-39-18

Resource Properties
 Input Path: /home/menashe/Downloads/ALL-CDIS
 Input Size: 15519 MB
 Timestamp: 2015-01-30-15-23-53
 Encoding: UTF-8
 CHOP: true

Indexes
 Up-to-date: true
 TEXTINDEX: true
 ATTRINDEX: true
 FTINDEX: false
 LANGUAGE: English
 STEMMING: false
 CASESENS: false
 DIACRITICS: false
 STOPWORDS: 
 UPDINDEX: false
 MAXCATS: 1000
 MAXLEN: 96

Reply via email to