Case insensitive filter query with Objectify + goo

2019-04-10 08:58发布

Is there an easy way to do a case insensitive filter query with Objectify + google appengine (Java)? Essentially this is what I am trying to do except that I need the filter on email to be case insensitive.

Objectify objectifyService = ObjectifyService.begin();
objectifyService.query(AppUser.class).filter("email", email).get();

2条回答
戒情不戒烟
2楼-- · 2019-04-10 09:23

You need to store your email address in a normalized (lowercase or uppercase, for instance) form in the datastore, and query on that. If you also need the original unmodified email address, you should store both separately.

查看更多
爷、活的狠高调
3楼-- · 2019-04-10 09:23

In case of queries we convert everything to a similar case and then do the comparison.

select * from account where upper(email) = upper('test@gmail.com');

In your case you could try.

objectifyService.query(AppUser.class).filter("upper(email)", email.toUpperCase()).get();

I am not sure if this will work with Objectify, you could give it a try.

查看更多
登录 后发表回答