Skip to content

Commit

Permalink
fix parse of nested multiple binary ops (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
barelshmuely committed Dec 28, 2023
1 parent 1b26601 commit 80651eb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pycsw/ogc/fes/fes1.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ def _get_comparison_expression(elem):
return expression

queries = []
queries_nested = []
values = []

LOGGER.debug('Scanning children elements')
Expand Down Expand Up @@ -301,8 +300,10 @@ def _get_comparison_expression(elem):
tagname = ' %s ' % child_tag_name.lower()
if tagname in [' or ', ' and ']: # this is a nested binary logic query
LOGGER.debug('Nested binary logic detected; operator=%s', tagname)
queries_nested = []
for child2 in child.xpath('child::*'):
queries_nested.append(_get_comparison_expression(child2))
LOGGER.debug('Nested binary logic queries: %s', queries_nested)
queries.append('(%s)' % tagname.join(queries_nested))
else:
queries.append(_get_comparison_expression(child))
Expand Down
3 changes: 2 additions & 1 deletion pycsw/ogc/fes/fes2.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def _get_comparison_expression(elem):
return expression

queries = []
queries_nested = []
values = []

LOGGER.debug('Scanning children elements')
Expand Down Expand Up @@ -319,8 +318,10 @@ def _get_comparison_expression(elem):
tagname = ' %s ' % child_tag_name.lower()
if tagname in [' or ', ' and ']: # this is a nested binary logic query
LOGGER.debug('Nested binary logic detected; operator=%s', tagname)
queries_nested = []
for child2 in child.xpath('child::*'):
queries_nested.append(_get_comparison_expression(child2))
LOGGER.debug('Nested binary logic queries: %s', queries_nested)
queries.append('(%s)' % tagname.join(queries_nested))
else:
queries.append(_get_comparison_expression(child))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- PYCSW_VERSION -->
<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xs="http://www.w3.org/2001/XMLSchema" 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:SearchStatus timestamp="PYCSW_TIMESTAMP"/>
<csw:SearchResults numberOfRecordsMatched="1" numberOfRecordsReturned="1" nextRecord="0" recordSchema="http://www.opengis.net/cat/csw/2.0.2" elementSet="full">
<csw:Record>
<dc:identifier>urn:uuid:94bc9c83-97f6-4b40-9eb8-a8e8787a5c63</dc:identifier>
<dc:type>http://purl.org/dc/dcmitype/Dataset</dc:type>
<dc:title>Mauris sed neque</dc:title>
<dc:subject scheme="http://www.digest.org/2.1">Vegetation-Cropland</dc:subject>
<dct:abstract>Curabitur lacinia, ante non porta tempus, mi lorem feugiat odio, eget suscipit eros pede ac velit.</dct:abstract>
<dc:date>2006-03-26</dc:date>
<ows:BoundingBox crs="urn:x-ogc:def:crs:EPSG:6.11:4326">
<ows:LowerCorner>47.595 -4.097</ows:LowerCorner>
<ows:UpperCorner>51.217 0.889</ows:UpperCorner>
</ows:BoundingBox>
</csw:Record>
</csw:SearchResults>
</csw:GetRecordsResponse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<GetRecords service="CSW" version="2.0.2" maxRecords="10" resultType="results" xmlns="http://www.opengis.net/cat/csw/2.0.2" xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd">
<Query typeNames="csw:Record">
<ElementSetName>full</ElementSetName>
<Constraint version="1.0.0">
<ogc:Filter>
<ogc:And>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>dc:type</ogc:PropertyName>
<ogc:Literal>http://purl.org/dc/dcmitype/Image</ogc:Literal>
</ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>dc:type</ogc:PropertyName>
<ogc:Literal>http://purl.org/dc/dcmitype/Dataset</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
<ogc:Or>
<ogc:PropertyIsLike wildCard="%" singleChar="_" escapeChar="\">
<ogc:PropertyName>dc:title</ogc:PropertyName>
<ogc:Literal>Mauris%</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:PropertyIsLike wildCard="%" singleChar="_" escapeChar="\">
<ogc:PropertyName>dc:title</ogc:PropertyName>
<ogc:Literal>%neque</ogc:Literal>
</ogc:PropertyIsLike>
</ogc:Or>
</ogc:And>
</ogc:Filter>
</Constraint>
</Query>
</GetRecords>

0 comments on commit 80651eb

Please sign in to comment.