Google App Engine综合索引重新使用 [英] Google App Engine Composite Index re-use

查看:110
本文介绍了Google App Engine综合索引重新使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有特定模型的Google App Engine应用程序,我们称之为游戏。
它是指足球比赛,其日期,推荐人(参考),2个俱乐部(参考),比分,阶段(参考),比赛(参考)和赛季(参考)列表。换句话说,它有几个字段,我打算通过高级搜索页面进行搜索。

例如,如果有人想按季搜索所有游戏(比如说:2008/2009)和按日期(比如2009年1月1日之后),我应该解析GET变量,并提出如下内容:

  games = Game.all()
//解析GET变量。
if(variables.hasFilter(season)
games.filter(game_season =,season)
if(variables.hasFilter(after_date)
games.filter (game_date>,after_date)

它需要一个特定的组合索引:

   -  kind:游戏
属性:
- name:game_season
- name:game_date

现在,如果有人想要搜索季节和俱乐部,它将与上述内容相同,只不过它需要其他复合index:

   -  kind:游戏
属性:
- 名称:game_season
- 名称:game_club

现在,如果有人想搜索季节,日期和俱乐部,另一个组合索引:

   -  kind:游戏
属性:
- 名称:game_season
- name:game_date
- name:game_club

我的问题是:如果我有第三个索引dy和服务查询,我可以删除两个第一个索引,因为它可以用于提供上述三个高级搜索,或者Google App Engine会生成NeedIndexError,因为它不知道如何重用第三个索引来为第一个索引两个高级搜索?



问题是我想创建一个高级搜索的几个领域(比如6日期,赛季,比赛,俱乐部,阶段,比分)。这需要将索引与两个实体组合,包含3个实体的索引组合等,直到组合所有实体的最终索引。

问题:


  • GAE能否真正重用复合索引,所以通过为6个实体生成一个复合索引,我不必为5,4,3和2个实体生成该索引的简单版本?


  • 如果没有,是否有更好的方法来解决这个问题?我打算做的一件事就是插入空白过滤器,例如在特定季节和俱乐部内搜索游戏:

    games = Game。 all()

    //解析GET变量。
    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(

    $ b games.filter(game_club =*)




我还没有实现这个解决方法,因为我认为它很丑,这意味着它不是解决这个问题的最好方法(另外,我还不知道如何实现通配符)。



感谢您对此问题的任何意见。

解决方案

因为App Engine数据存储区无模式,后一个索引不能用于满足前一个索引的查询,因为它只索引定义了所有三个属性的实体。



插入'空'过滤器也不行,因为它只会返回那些为这些属性设置空字符串的实体,而不是返回具有任何值的实体(这似乎是你想要的)。



一种选择是依赖合并连接策略 - 只要没有不等式过滤器或排序顺序,App Engine就可以使用任意数量的相等过滤器执行查询,没有自定义索引。另一个选择是使用一个StringListProperty,填充适用于该实体的所有标志,并在列表中执行查询。


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.

这篇关于Google App Engine综合索引重新使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆