使用 JDOQL 获取“包含”结果时出现问题要求
我正在使用 Google App Engine 进行项目,并且需要对数据库进行一些查询。我使用JDOQL来询问数据库。就我而言,我想获取包含子字符串“array”的大学。我认为我的查询有错误,因为它按字母顺序返回大学名称,而不是包含子字符串的大学名称。
Query query = pm.newQuery("SELECT FROM " + University.class.getName() + " WHERE name.contains("+array+") ORDER BY name RANGE 0, 5");
有人可以告诉我我的查询有什么问题吗?
感谢您的帮助!
编辑
我有一个大学商店列表,我有一个建议框,我们可以在其中按他的名字请求一所大学。我想自动完成请求的名称。
I am using Google App Engine for a project and I need to do some queries on the database. I use the JDOQL to ask the database. In my case I want to obtain the university that contains the substring "array". I think my query has a mistake because it returns the name of universities in the alphabetical order and not the ones containing the substring.
Query query = pm.newQuery("SELECT FROM " + University.class.getName() + " WHERE name.contains("+array+") ORDER BY name RANGE 0, 5");
Could someone tell me what's wrong in my query?
Thank you for your help!
EDIT
I have a list of universities store and I have a suggestbox where we can request a university by his name. And I want to autocomplete the requested name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
App Engine 不支持全文搜索,您应该为问题 217。然而,部分解决方法是可能的。对于你的情况,我认为这是一个很好的选择。
首先,调整你的模型,使名称也有一个小写(或大写)版本——我假设它被称为 lname。除非您希望查询区分大小写。
然后你这样查询:
App engine does not support full-text searches, you should star issue 217. However, A partial workaround is possible. And in your case I think it is a good fit.
First thing, adjust your model such that there is a lower (or upper case) version of the name as well -- I will assume it is called lname. Unless you want your queries to be case-sensitive.
Then you query like this:
正确的方法是这样的 -
(注意 - 在这种情况下
:p
是一个 隐式参数名称,您可以替换为任何名称)The correct way to do this is like this -
(note- In this case the
:p
is an implicit param name you can replace with any name)