2012-06-05 53 views
1

我有一些实体,我希望做一个祖先查询并通过“>”运算符筛选参数。 有问题的实体继承另一个对象(我认为这不重要)。下面是我的实体类:Appengine查询返回没有匹配的索引 - 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查询:

SELECT * FROM地方PersonnelInfo timeUpdated> 0

,我回到单位,这让我相信,在创建索引。我在这里做错了什么?任何帮助,将不胜感激!

回答

2

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

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

yup!再次贴上救援的标签。谢啦!我的查询从未在开发模式下运行 – Patrick

+0

当您必须创建多属性索引时,一点困惑。例如,如果你对y()进行查询,那么query(someclass).filter(“time”,time).filter(“person”,person);对? – Patrick

+0

本页有很多讨论:https://developers.google.com/appengine/docs/java/datastore/queries结果是,当您使用多个属性(或prop +祖先)时,您需要索引,除了查询引擎有时足够聪明以使用单一属性索引进行优化。我相信可以优化两个属性的平等查询。 – stickfigure

相关问题