问题描述
我使用 Android Studio 创建了一个 Android 项目及其后端 AppEngine Endpoints.我有一个正在使用 Objectify 的数据存储.系统运行良好,直到我在查询中添加了过滤器(仅显示特定的给定电子邮件).
I used Android Studio to create both an Android project, and its backend AppEngine Endpoints counterpart. I have a datastore for which I am using Objectify. The system worked great, until I added a filter to my Query (to show only specific given emails).
Query<Report> query = ofy().load().type(Report.class).filter("email", user.getEmail()).order("email").order("-when").limit(limit);
这是 POJO 数据存储实体:
This is the POJO Datastore Entity:
@Entity
public class Report {
@Id
Long id;
String who;
@Index
Date when;
String what;
@Index
String email;
}
但是,当我尝试测试它时,我从 Google API Explorer 收到了这样的错误:
However, I receive such an error from the Google API Explorer when I attempt to test it:
com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.
The suggested index for this query is:
<datastore-index kind=\"AccessReport\" ancestor=\"false\" source=\"manual\">
<property name=\"email\" direction=\"asc\"/>
<property name=\"when\" direction=\"desc\"/>
</datastore-index>
据我所知,我只需要创建一个复合索引,包括特定字段的电子邮件和时间,以及它们的特定排序方向.
As I understand it, I simply need to create a composite index including the specific fields email and when, with their specific sort direction.
但是,我找到的大多数文档都告诉我要编辑 datastore-indexes.xml
.
However, most documentation that I find tell me to edit datastore-indexes.xml
.
App Engine 为实体的每个属性预定义了一个简单的索引.一个App Engine 应用程序可以在索引中定义更多自定义索引配置文件名为datastore-indexes.xml,在您的应用程序的/war/WEB-INF/appengine-generated 目录.
不幸的是,这个文件似乎不存在于我的项目中.
Unfortunately, this file does not seem to exist anywhere in my project.
有没有人熟悉在使用 Android Studio 时更改此设置的方法?
Is anyone familiar with the way to change this when working with Android Studio?
推荐答案
创建 datastore-indexes.xml 文件并将其放在 /WEB-INF/
文件夹中.内容将如下所示:
Create datastore-indexes.xml file and put it in /WEB-INF/
folder. The content will look like this:
<datastore-indexes
autoGenerate="true">
<datastore-index kind=\"AccessReport\" ancestor=\"false\" source=\"manual\">
<property name=\"email\" direction=\"asc\"/>
<property name=\"when\" direction=\"desc\"/>
</datastore-index>
</datastore-indexes>
这篇关于在基于 Android-Studio 的项目中为 AppEngine 创建复合索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!