我正在遵循 Udacity 的使用 Java 开发可扩展应用程序教程,并尝试通过多个属性创建查询,但它不起作用。
这是 Api 方法:
@ApiMethod(name = "filterPlayground",path = "filterPlayground",httpMethod = HttpMethod.POST)
public List<Conference> filterPlayground()
{
Query<Conference>query = ofy().load().type(Conference.class).order("name");
query.filter("city = ","London");
query.filter("topics =", "Medical Innovations");
query.filter("month = ", 6);
return query.list();
}
以下是 session 模型中的字段:
private static final String DEFAULT_CITY = "Default City";
@Index private List<String> topics;
@Index(IfNotDefault.class) private String city = DEFAULT_CITY;
@Index private int month;
它只显示所有 session 。我不明白为什么这不起作用。顺便说一句,当我部署到本地主机时,datastore-indexes-auto.xml 始终为空。
我希望有人能帮助我解决这个问题。 问候,
最佳答案
我也在学习同一门类(class),并且在这一点上也遇到了困难。无论我做什么,datastore-indexes-auto.xml 都没有被创建!
我的解决方法如下:
1) 在文件夹/conference/src/main/webapp/WEB-INF/中创建一个 datastore-indexes.xml 文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<datastore-indexes
autoGenerate="true">
<datastore-index kind="Conference" ancestor="false">
<property name="city" direction="asc" />
<property name="topics" direction="asc" />
<property name="month" direction="asc" />
<property name="name" direction="asc" />
</datastore-index>
</datastore-indexes>
(但是,autoGenerate="true"似乎没有效果)
2) 部署到appsot
这样,您上面发布的查询就适合我。我同意 - 类(class)的 GAE 版本似乎有些不同,因为我遇到了几个问题(即我似乎没有本地数据存储,但每个本地主机执行都在访问我的 appspot 数据存储..) .
关于java - App Engine 不生成复合索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25445166/