Appengine查询返回没有匹配的索引 - Objectify

时间:2012-06-05 23:28:09

标签: google-app-engine gql objectify

我有一些实体,我希望通过“>”进行祖先查询并过滤参数运营商。 有问题的实体继承了另一个对象(我认为这不重要)。以下是我的实体类:

@Indexed
public class ValidatedObject {

public Long timeCreated=System.currentTimeMillis();
public Long timeUpdated=System.currentTimeMillis();


public Long getTimeUpdated() {
    return timeUpdated;
}
public void setTimeUpdated(Long timeUpdated) {
    this.timeUpdated = timeUpdated;
}
public Boolean validated=false;
@Unindexed
public String validatedID;
@Unindexed
private Long validatedTime;
@Unindexed
private String creatorID;

public Long getTimeCreated() {
    return timeCreated;
}
public void setTimeCreated(Long timeCreated) {
    this.timeCreated = timeCreated;
}
public boolean isValidated() {
    return validated;
}
public void setValidated(boolean validated) {
    this.validated = validated;
}
public String getValidatedID() {
    return validatedID;
}
public void setValidatedID(String validatedID) {
    this.validatedID = validatedID;
}
public Long getValidatedTime() {
    return validatedTime;
}
public void setValidatedTime(Long validatedTime) {
    this.validatedTime = validatedTime;
}
public String getCreatorID() {
    return creatorID;
}
public void setCreatorID(String creatorID) {
    this.creatorID = creatorID;
}

}



@Cached
@Entity
public class PersonnelInfo extends ValidatedObject{

  @Id
  public String keyName; 

@Parent Key<Department> department;
private Long fdID;

@Unindexed
private String userKeyName;

private String firstName;
private String lastName;
@Unindexed
private String address,city,county,state;
@Unindexed
private String cellPhone,homePhone,otherPhone;


public PersonnelInfo(){

}
public PersonnelInfo(String email){
    keyName=email;
}

@Override
public Long getTimeUpdated() {
    return timeUpdated;
}
@Override
public void setTimeUpdated(Long time) {
    timeUpdated=time;
}


}

我的查询代码如下:

Query<PersonnelInfo> q = ofy.query(PersonnelInfo.class).ancestor(tmp).filter("timeUpdated >",     lastSync);

我每次都会收到“找不到匹配的索引”错误。没有过滤器,查询工作正常。有些实体缺少“timeUpdated”字段,因为我更改了架构。在使用timeUpdated值更改架构后,已创建一些实体,并且不会返回这些实体。此外,我可以在数据存储区查看器上执行GQL查询,如下所示:

选择*其中FROM PersonnelInfo timeUpdated&gt; 0

我回复了实体,这让我相信索引已经创建了。我在这做错了什么?任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

您需要在datastore-indexes.xml中定义多属性索引。在开发模式下运行查询时,应将其添加到datastore-indexes-auto.xml,但结果应如下所示:

<datastore-index kind="PersonnelInfo" ancestor="true">
    <property name="timeUpdated" direction="asc"/>
</datastore-index>