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