2013-03-27 36 views
4

我有實體:Google App Engine,Java Datastore Query:如何做SQL Like語句?

Entity e = new Entity("Item"); 
e.setProperty("Description", Description); 

,我試圖進行關鍵字搜索。例如,如果我有「abc」,「eabcd」和「abc block」,當我執行搜索「abc」時,它應該返回全部三個。

如果我使用SQL,我要說的是這樣的:

Select * from Item where Description like "%"+keyword+"%" 

我知道我能做到這一點,但這隻會返回「ABC」。

public static Iterable<Entity> SearchItems(String Description) { 
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); 
    Query q = new Query("Item").addFilter("Description", 
      FilterOperator.EQUAL, Description); 
    return ds.prepare(q).asIterable(); 
} 

我該怎麼辦?

P.S.我已經看到了這一點,但這不是特別有用。 Google App Engine and SQL LIKE

回答

4

您需要的是full text search,而App Engine數據存儲不支持該功能。您需要使用App Engine Search API來做such queries

但是,API不支持將全文查詢應用於數據存儲,您需要在indexed documents中構建和存儲數據。您可能需要考慮複製數據存儲中的數據並將其再次存儲在索引文檔存儲中。

+0

有趣。謝謝您的回覆! 我希望他們最終會實現一個「喜歡」搜索的功能,因爲這對於如此多的功能非常重要。 (尤其對於我們這些剛接觸GAE並習慣於在SQL中進行搜索的人)。 – user2214756 2013-03-28 06:11:43