将@index添加到字段后,java Objectify筛选器不起作用
我正在尝试使用Objectify从数据存储中获取一个过滤列表,但一直获取一个空列表。我尝试添加@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
}
}
数据存储索引。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>
有人知道如何修复此问题以使筛选器查询正常工作吗
# 1 楼答案
如果在数据已存储在数据存储中之后对属性进行索引,则查询将继续为空。这是因为应用程序引擎在保存所有实体时对其进行索引。更改索引属性列表后,必须重新保存所有实体