2
我试图使用Objectify从数据存储中获取过滤列表,但不断收到空列表。我尝试添加@index并创建一个datastore-index.xml文件,但仍然未定义。在将@index添加到字段后,Objectify过滤器不工作
我的清单类:
@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>
任何人都知道如何解决这要获得过滤器查询的工作?
谢谢!这让它显示新的数据,但现在它只是返回所有新的数据,而不是那些> 15.你知道那里可能是错的吗? [编辑]我改成它15.0,它的工作。卫生署! – Mark 2014-11-02 05:06:29
是的,你必须小心数据的类型。如果你存储双打,那么你应该在你的过滤器中使用双精度。 – 2014-11-02 15:07:52