开发者

Google App Engine Composite Index re-use

I have a Google App Engine app with a certain Model, let's call it Game. It refers to a football game, its date, referree (a Reference), a list of 2 Clubs (References), the score, its Phase (Reference), Competition (Reference) and Season (Reference). In other words, it has several fields that I intend to make it searchable through an advanced search page.

For instance, if someone wants to search all games by Season (say: 2008/2009) and by date (say after 1/1/2009), I should parse the GET variables and come up with something like:

games = Game.all()   
// parse GET variables. 
if (variables.hasFilter("season")    
games.filter("game_season = ", season)
if (variables.hasFilter("after_date")    
games.filter("game_date > ", after_date)

It requires a specific composite index:

- kind: Game
  properties:
  - name: game_season
  - name: game_date

Now, if someone wants a search for Season and Club, it would be the same as above, except that it requires another composite index:

- kind: Game
  properties:
  - name: game_season
  - name: game_club

Now, if someone wants to search for Season, a date and a Club, it requires even another composite index:

- kind: Game
  properties:
  - name: game_season
  - name: game_date
  - name: game_club

My question is: if I have the third index ready and serving queries, can I delete the two first indexes, as it could be used to serve the aforementioned three advanced searches, or will Google App Engine generate the NeedIndexError because it doesn't know how to reuse the third index to serve the first two advanced searches?

The 开发者_高级运维problem is that I would like to create an advanced search for several fields (say 6 - date, season, competition, club, phase, score). That would require a combination of indexes with two entities, a combination of indexes with 3 entities, etc until a final index that combines all entities.

Questions:

  • Can GAE really reuse the composite indexes, so that by generating, say, a composite index for 6 entities, I don't have to generate simpler versions of that index for 5, 4, 3 and 2 entities?

  • If not, is there a better way to address this problem? One thing I'm planning on doing is to insert "blank" filters, for instance in a search for games within a certain Season and a Club:

    games = Game.all()

    // parse GET variables. if (variables.hasFilter("season")

    games.filter("game_season = ", season) else games.filter("game_season = " *)

    if (variables.hasFilter("date")

    games.filter("game_date = ", date) else games.filter("game_date = " *)

    if (variables.hasFilter("club")

    games.filter("game_club = ", club) else games.filter("game_club = " *)

I haven't implemented this workaround because I think it's ugly and that means that it's not the best way to deal with this problem. (also, I still don't know how to implement the wildcard stuff).

Thanks for any input on this problem.


Because the App Engine datastore is schemaless, the latter index can't be used to satisfy queries for the former ones, because it indexes only entities that have all three properties defined.

Inserting 'empty' filters won't work, either, because it will only return entities that have empty strings set for those properties, rather than returning entities with any value (which seems to be what you want).

One option is to rely on the merge join strategy - App Engine can execute a query with any number of equality filters, as long as there are no inequality filters or sort orders, without a custom index. Another option is to use a StringListProperty, populated with all the 'flags' that apply to the entity, and perform queries on the list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜