Google App Engine - 关键字搜索+其他属性排序 [英] Google App Engine - keyword search + ordering on other properties

查看:118
本文介绍了Google App Engine - 关键字搜索+其他属性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class MyEntity(db.Model):
关键字= db.StringListProperty()
sortProp = db.FloatProperty()

我有这样做的关键字搜索过滤器:

$ $ p $ code query = MyEntity.all()\
.filter ('关键字> =',unicode(kWord))\
.filter('keywords <',unicode(kWord)+ u\\\�)\
.order('关键字')

这很好。我遇到的问题是,如果我尝试使用'sortProp'命令:

  .order( 'sortProp')

排序不起作用。我意识到为什么 - 文档明确指出这是不可能的,并且在使用具有多值属性的平等过滤器时(从Google文档中)忽略排序顺序:

一个重要的警告是在多值属性上使用等式过滤器和
排序顺序的查询。在那些查询中,排序
的顺序被忽略。对于单值属性,这是一个简单的
优化。每个结果对于属性
具有相同的值,因此结果不需要进一步排序。但是,多值
属性可能会有其他值。由于排序顺序为
,查询结果可能会以不同顺序返回
,而不是排序顺序。 (恢复被删除的排序顺序
将会很昂贵,并且需要额外的索引,而这个用例是
罕见的,所以查询规划器将它关闭。)


我的问题是:有没有人知道对此有一个很好的解决方法?有没有更好的方法来做一个关键字搜索,以规避这种限制?我真的很想结合使用关键字和其他属性的排序。我能想到的唯一解决方案是在查询后对列表进行排序,但如果这样做,我将失去对查询进行偏移的能力,如果数据集很大,我甚至可能无法获得排序顺序最高的结果。 / p>

感谢您的提示!

解决方案

正确标记化,干扰和标准化你的字符串,并对它们进行相等比较。


Say I have an entity that looks a bit like this:

class MyEntity(db.Model):
    keywords            = db.StringListProperty()
    sortProp            = db.FloatProperty()

I have a filter that does a keyword search by doing this:

query = MyEntity.all()\
                .filter('keywords >=', unicode(kWord))\
                .filter('keywords <',  unicode(kWord) + u"\ufffd")\
                .order('keywords')

Which works great. The issue I'm running into is that if I try to put an order on that using 'sortProp':

                .order('sortProp')

ordering has no effect. I realize why - the documentation specifically says this is not possible and that sort order is ignored when using equality filters with a multi-valued property (from the Google docs):

One important caveat is queries with both an equality filter and a sort order on a multi-valued property. In those queries, the sort order is disregarded. For single-valued properties, this is a simple optimization. Every result would have the same value for the property, so the results do not need to be sorted further. However, multi-valued properties may have additional values. Since the sort order is disregarded, the query results may be returned in a different order than if the sort order were applied. (Restoring the dropped sort order would be expensive and require extra indices, and this use case is rare, so the query planner leaves it off.)

My question is: does anyone know of a good workaround for this? Is there a better way to do a keyword search that circumvents this limitation? I'd really like to combine using keywords with ordering for other properties. The only solution I can think of is sorting the list after the query, but if I do that I lose the ability to offset into the query and I may not even get the results with the highest sort order if the data set is large.

Thanks for your tips!

解决方案

Instead of doing prefix matches, properly tokenize, stem and normalize your strings, and do equality comparisons on them.

这篇关于Google App Engine - 关键字搜索+其他属性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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