我尝试使用Objectify从数据存储中获取已过滤的列表,但继续获取一个空列表。我尝试添加@index并创建一个datastore-index.xml文件,但仍然未定义回来。
我的列表类:
@Entity
@Index
public class Listing {
@Id private Long id;
@Index private double price;
...
我的Api:
@Api(name ="xxxx")
@PersistenceCapable(detachable = "true")
public class ListingServiceAPI {
@ApiMethod(name = "getListings")
public List<Listing> getListings() {
return ofy().load().type(Listing.class).filter("price >", 15).list(); //this fails
//return ofy().load().type(Listing.class).limit(3).list(); //this works
}
}
数据存储-indexes.xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<datastore-indexes autoGenerate="true">
<datastore-index kind="Listing" ancestor="false">
<property name="price" direction="asc" />
<property name="category" direction="asc" />
</datastore-index>
</datastore-indexes>
有人知道如何解决此问题以使过滤器查询起作用吗?
答案 0 :(得分:2)
如果在数据已存储在数据存储区中后将属性编入索引,则查询将继续为空。发生这种情况是因为App Engine会在保存所有实体时为其编制索引。在更改索引属性列表后,您必须重新保存所有实体。