my2iu / Jinq

LINQ-style queries for Java 8
Other
660 stars 71 forks source link

case insensitive in strings #41

Closed georgemoralis closed 7 years ago

georgemoralis commented 7 years ago

I am looking a way to search string functions (compare , startsWith ) with case insensitive. Is there a a way to do that?

my2iu commented 7 years ago

It would be something like

db.streamAll(em, Customer.class)
   .where(c -> c.getName().toUpperCase().startsWith(prefix.toUpperCase()) )

Note: In order to do this query efficiently though, you should store the names in the database already in upper-case. Then, you can use indices to do the search. The query shown above involves scanning though the whole database to do the case-insensitive search.