pygeoapi icon indicating copy to clipboard operation
pygeoapi copied to clipboard

CQL-TEXT does not work with the NOCASE keyword for case (in)sensitive searches

Open webb-ben opened this issue 3 years ago • 6 comments

Description As per CQL predicates, the CQL comparisons should default nocase: true. Instead, this is ignored, and specifying NOCASE produces an error. The only way I am able to get case insensitive searches with cql-text are with ILIKE.

Steps to Reproduce Use NOCASE parameter: https://reference.geoconnex.us/collections/states/items?filter=name%20LIKE%20%27NEW%%27%20NOCASE%20true

Expected behavior name LIKE new is the same as name LIKE New is the same as name ILIKE new is the same as name LIKE new NOCASE true

Screenshots/Tracebacks image

Environment

  • OS: MacOS Ventura/Mac M1
  • Python version: docker/3.10
  • pygeoapi version: latest/0.15.0

Additional context I have not tested this with CQL-JSON or Elasticsearch.

webb-ben avatar Mar 14 '23 15:03 webb-ben

This is confirmed with demo:

http "https://demo.pygeoapi.io/master/collections/lakes/items?f=json&filter=name LIKE '%baika%' NOCASE true"
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Content-Crs: <http://www.opengis.net/def/crs/OGC/1.3/CRS84>
Content-Language: en-US
Content-Length: 108
Content-Type: application/json
Date: Wed, 23 Aug 2023 15:33:13 GMT
Server: gunicorn
X-Powered-By: pygeoapi 0.16.dev0

{
    "code": "InvalidParameterValue",
    "description": "Bad CQL string : name LIKE '%BAika%' NOCASE true"
}

Neither ILIKE is working for me:

http "https://demo.pygeoapi.io/master/collections/lakes/items?f=json&filter=name ILIKE '%baika%' NOCASE true"
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Content-Crs: <http://www.opengis.net/def/crs/OGC/1.3/CRS84>
Content-Language: en-US
Content-Length: 109
Content-Type: application/json
Date: Wed, 23 Aug 2023 15:40:42 GMT
Server: gunicorn
X-Powered-By: pygeoapi 0.16.dev0

{
    "code": "InvalidParameterValue",
    "description": "Bad CQL string : name ILIKE '%BAika%' NOCASE true"
}

francbartoli avatar Aug 23 '23 15:08 francbartoli

@francbartoli The mention of ILIKE should be taken separate from the CQL vocabulary for NOCASE. The CQL term NOCASE does not work. Because of how CQL is processed for Postgres, the SQL term ILIKE allows for nocase-like CQL queries.

curl -I -X GET "https://demo.pygeoapi.io/master/collections/lakes/items?f=json&filter=name%20ILIKE%20%27%baika%%27"
HTTP/2 200 
access-control-allow-origin: *
content-crs: <http://www.opengis.net/def/crs/OGC/1.3/CRS84>
content-language: en-US
content-type: application/json
date: Wed, 23 Aug 2023 18:51:23 GMT
server: gunicorn
x-powered-by: pygeoapi 0.16.dev0
content-length: 39637

webb-ben avatar Aug 23 '23 18:08 webb-ben

@webb-ben after several tests, I found out that:

  1. We are atm using the ecql parser pygeofilter.parsers.ecql.parse despite it is available pygeofilter.parsers.cql2_text.parse. @constantinius I'm wondering if it makes sense the switch to the latter in pygeoapi
  2. pygeofilter.parsers.ecql.parse is supporting case sensitive by default with LIKE and case insensitive with ILIKE
(Pdb) cqltext = "name LIKE '%baika%'"
(Pdb) print(pygeofilter.parsers.ecql.parse(cqltext))
Like(lhs=ATTRIBUTE name, pattern='%baika%', nocase=False, wildcard='%', singlechar='.', escapechar='\\', not_=False)
(Pdb) cqltext = "name ILIKE '%baika%'"
(Pdb) print(pygeofilter.parsers.ecql.parse(cqltext))
Like(lhs=ATTRIBUTE name, pattern='%baika%', nocase=True, wildcard='%', singlechar='.', escapechar='\\', not_=False)
  1. However pygeofilter.parsers.cql2_text.parse doesn't support NOCASE
(Pdb) cqltext = "name LIKE '%baika%' NOCASE true"
(Pdb) print(pygeofilter.parsers.cql2_text.parse(cqltext))
*** lark.exceptions.UnexpectedToken: Unexpected token Token('__ANON_4', 'NOCASE') at line 1, column 21.
Expected one of: 
        * $END
        * AND
        * OR
Previous tokens: [Token('SINGLE_QUOTED', "'%baika%'")]

francbartoli avatar Aug 23 '23 19:08 francbartoli

As per RFC4, this Issue has been inactive for 90 days. In order to manage maintenance burden, it will be automatically closed in 7 days.

github-actions[bot] avatar Mar 10 '24 21:03 github-actions[bot]

@francbartoli Any update on this? Believe this remains unresolved.

webb-ben avatar Mar 22 '24 07:03 webb-ben

deferring to @ricardogsilva who managed to fix some bugs on the ecql parser

francbartoli avatar Mar 22 '24 07:03 francbartoli

This Issue has been inactive for 90 days. As per RFC4, in order to manage maintenance burden, it will be automatically closed in 7 days.

github-actions[bot] avatar Jun 23 '24 03:06 github-actions[bot]

As per RFC4, this Issue has been closed due to there being no activity for more than 90 days.

github-actions[bot] avatar Jun 30 '24 03:06 github-actions[bot]