1

I have GIS API based on OpenLayers and GeoServer. I want to perform an Ajax request in order to get all the features that have a given keyword.

For example, I could use the CQL filter:

name LIKE '%Setúbal%'

And I will get the feature corresponding to the portuguese district of "Setúbal".

Now, I wanted to simplify a bit and allow myself to write "setúbal".

I use the following CQL filter:

strToLowerCase(name) LIKE '%setúbal%'

It works fine, because the CQL function "strToLowerCase" successfully converts the text of the feature to lower case.

--- UNTIL HERE, EVERYTHING WORKS FINE... THE PROBLEM COMES NEXT ---

As you may have noticed, I want to simplify further by only writing "setubal" without the accented "u" ("ú").

I looked into the Filter Function Reference of Geoserver and I found the "strReplace" method, which seemed to be exactly what I needed to replace the accented letters of the feature's attribute.

So, I tried these CQL filters:

// Replace the accented "u" and convert to lower case
strToLowerCase(strReplace(name, ú, u, true)) LIKE '%setubal%'

// Only replace the accented "u"
strReplace(name, ú, u, true) LIKE '%setubal%'

But neither of them work and I get this parser error:

<?xml version="1.0" encoding="UTF-8"?>
<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">
    <ServiceException>Could not parse CQL filter list. Lexical error at line 1, column 18. Encountered: "\u00fa" (250), after : "" Parsing : strReplace(name, ú, u, true) LIKE '%setubal%'.</ServiceException>
</ServiceExceptionReport>

I thought that the problem might be in using an accented letter in a CQL filter, and tried this:

strReplace(name, e, u, true) LIKE '%setubal%'

And even so, I get a parser error (but different than the previous one):

<?xml version="1.0" encoding="UTF-8"?>
<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">
    <ServiceException>java.lang.RuntimeException: java.lang.NullPointerException: PropertyDescriptor is null - did you request a property that does not exist? java.lang.NullPointerException: PropertyDescriptor is null - did you request a property that does not exist? PropertyDescriptor is null - did you request a property that does not exist?</ServiceException>
</ServiceExceptionReport>

Am I using the "strReplace" function in a wrong way? Could anybody help with this issue, please? I want to replace accented characters in the CQL filter.

  • 1
    don't you need quotes around the u's ? – Ian Turton Aug 18 '15 at 17:30
  • Hello @iant. You are absolutely right. I had tried with double-quotes (") and it didn't work either. Now, I have tried with simple-quotes (') and it worked. I can't believe I lost so much time around something so simple. Thank you very much. :) – joaorodr84 Aug 18 '15 at 17:53
  • Write that as an answer so it will be easier to find from archives. – user30184 Aug 19 '15 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.