[Geoserver-users] PropertyIsLike Wildcard Does Not Capture Carriage Return

Hi Everyone,

I’m having a problem using a PropertyIsLike OGC Filter in a WFS GetFeature request when the data includes carriage returns and linefeeds. I would expect that the wildcard should capture carriage returns, but that does not appear to be the case unless I’m misunderstanding something.

As an example. The following Filter returns the record I am looking for because I explicitly search for the carriage return linefeed:

adr_label

But this Filter does not return the record since I am only including the wildcard character:

adr_label

First, am I missing something obvious here and going about this wrong? Second, is there an easy way to accomplish this task without chaining a bunch of PropertyIsLikes together in a long ?

I appreciate any insight, thanks so much!

Matt

The filter is here https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/filter/LikeFilterImpl.java

The eventual conversion to a java pattern is here https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/filter/LikeToRegexConverter.java and there is a method to recognize and fix special characters - and newline is not on the list.

Looking a little more at java Pattern (https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) matcher used:

  • The newline character is special to the java pattern matcher, so support would need to be added to LikeToRegexConverter
  • The pattern matcher has a flag for MULTILINE which is not used

So you are not missing anything, support for multiline is not implemented / available.

As a workaround I suggest doing a string substitution using function call on your adr_label and pass the result to PropertyIsLike

Jody

Thank you so much, Jody, for the thorough reply. I was initially averse to using a function on the adr_label since I fear it would prevent database indexes on the column from being used… but then I realized I’m already using an strToLowerCase in my real code (though not my example here), so I suppose it may be a moot point :blush:

Thanks again, this is exactly what I was looking for!

From: Jody Garnett jody.garnett@anonymised.com
Sent: Thursday, April 1, 2021 10:50 AM
To: mcharton@anonymised.com
Cc: GeoServer Users geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] PropertyIsLike Wildcard Does Not Capture Carriage Return

The filter is here https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/filter/LikeFilterImpl.java

The eventual conversion to a java pattern is here https://github.com/geotools/geotools/blob/main/modules/library/main/src/main/java/org/geotools/filter/LikeToRegexConverter.java and there is a method to recognize and fix special characters - and newline is not on the list.

Looking a little more at java Pattern (https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) matcher used:

  • The newline character is special to the java pattern matcher, so support would need to be added to LikeToRegexConverter

  • The pattern matcher has a flag for MULTILINE which is not used

So you are not missing anything, support for multiline is not implemented / available.

As a workaround I suggest doing a string substitution using function call on your adr_label and pass the result to PropertyIsLike

Jody

Hi Jody,
that is true, assuming the filter is evaluated in memory, which would be the case if the data source is a shapefile.
But if there is a datastore behind it, that can delegate filtering to some other system, then the dynamic will be different (e.g., it
could be translated down to SQL).

Cheers
Andrea

···

Regards, Andrea Aime

== GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.