Python 获取错误“;无法满足查询--在/!=价值观;。如何解决这个问题?
问题:用户(B)需要一组用户(a)根据特定标准提供帮助。此标准由用户(A)在其配置文件中设置Python 获取错误“;无法满足查询--在/!=价值观;。如何解决这个问题?,python,google-app-engine,Python,Google App Engine,问题:用户(B)需要一组用户(a)根据特定标准提供帮助。此标准由用户(A)在其配置文件中设置 class UsersAProfiles(db.Model): industries = db.StringListProperty() #technology, etc. (total 20) agegroups = db.StringListProperty() #teenagers, etc. (total 10) tags = db.StringList
class UsersAProfiles(db.Model):
industries = db.StringListProperty() #technology, etc. (total 20)
agegroups = db.StringListProperty() #teenagers, etc. (total 10)
tags = db.StringListProperty() #cooking, etc.
(while each User A can enter at most 10 tags, but there is no limit on
what tags are used, e.g., sql, gym, etc. (limited by dictionary!)
... #there are many other properties
用户(B)设置单独存储的条件
class UserBRequestForHelp(db.Model):
myindustries = db.StringListProperty() #technology, etc. (<20)
myagegroups = db.StringListProperty() #teenagers, etc. (<10)
mytags = db.StringListProperty() #cooking, etc.
... #there are many other properties
但我得到了以下错误:
Cannot satisfy query -- too many IN/!= values.
我真的被困在这里,不知道如何解决这个问题。如何运行这样的查询。此外,我是否需要以不同的方式设计模型类,以便运行此类查询?如果是,请有人帮忙
提前谢谢你 使用IN创建查询时,GAE必须将该查询分解为多个“index=value”子查询,执行每个子查询并收集结果,就像它们是一次搜索一样。查询可以扩展到的子查询的数量有限制,并且。如果您正在创建包含31个子查询的查询,这就解释了为什么会遇到这种情况。换句话说,您的情况是len(userB_obj.myindustries)+len(userB_obj.myagegroups)+len(userB_obj.mytags)>30。对于上述问题,以下方法可能有用
class TAGS(db.Model):
UserAIds = db.StringListProperty()
在上面的例子中,每个标签都是关键。(标签=技术、青少年、烹饪等)i = 0
for industry in userB_obj.myindustries:
t1_obj[i] = TAGS.get_by_key_name(industry)
i = i + 1
(在上面的t1_obj[i]中,您拥有具有匹配行业的用户A配置文件列表)
(在上面的t2_obj[j]中,您拥有具有匹配年龄组的用户A配置文件列表)
(在上面的t3_obj[k]中,您拥有具有匹配标记的用户A配置文件列表)class MatchingUserAs(db.Model):
count = db.IntegerProperty(default=0)
source = db.StringProperty(default=None)
(在上面的模型类中,UserA id是键。此UserAids存储在t1_键[i]。UserAids,t2_键[j]。UserAids,t3_键[k]。UserAids)<"loop through t1_obj[i]">:
Matchkey = MatchingUserAs.get_or_insert(t1_obj[i].UserAId)
Matchkey.count = 1
Matchkey.source = 'industry'
Matchkey.put()
<"loop through t2_obj[j]">:
Matchkey = MatchingUserAs.get_or_insert(t2_obj[j].UserAId)
#the following if check has been added to avoid incrementing the counter
#when same UserAid is present in, say, t2_obj[0], and t2_obj[1], etc.
if(Matchkey.source != 'agegroup')
Matchkey.count = Matchkey.count + 1
Matchkey.source = 'agegroup'
Matchkey.put()
<"loop through t3_obj[j]">:
Matchkey = MatchingUserAs.get_or_insert(t3_obj[j].UserAId)
if(Matchkey.source != 'tags')
Matchkey.count = Matchkey.count + 1
Matchkey.source = 'tags'
Matchkey.put()
:
Matchkey=MatchingUserAs.get\u或\u insert(t1\u obj[i].UserAId)
Matchkey.count=1
Matchkey.source='行业'
Matchkey.put()
:
Matchkey=MatchingUserAs.get\u或\u insert(t2\u obj[j].UserAId)
#已添加以下if检查以避免计数器递增
#当相同的用户辅助存在于例如t2_obj[0]和t2_obj[1]等中时。
if(Matchkey.source!=“年龄组”)
Matchkey.count=Matchkey.count+1
Matchkey.source='agegroup'
Matchkey.put()
:
Matchkey=MatchingUserAs.get\u或\u insert(t3\u obj[j].UserAId)
if(Matchkey.source!=“标记”)
Matchkey.count=Matchkey.count+1
Matchkey.source='tags'
Matchkey.put()
上述代码示例中可能存在一些语法错误,特别是对于键和对象的使用;在某些情况下,还使用了伪代码。我只是想概述一下解决方案。希望这有帮助。欢迎分享任何意见。谢谢您提供的信息。非常感谢。我还想知道解决方案应该是什么。(刚刚想出了另一个解决方案(昨晚睡觉时思考这个解决方案,让潜意识思考:-))。我将很快公布答案。再次感谢您提供的信息!
k = 0
for tag in userB_obj.mytags:
t3_obj[k] = TAGS.get_by_key_name(tag)
k = k + 1
class MatchingUserAs(db.Model):
count = db.IntegerProperty(default=0)
source = db.StringProperty(default=None)
<"loop through t1_obj[i]">:
Matchkey = MatchingUserAs.get_or_insert(t1_obj[i].UserAId)
Matchkey.count = 1
Matchkey.source = 'industry'
Matchkey.put()
<"loop through t2_obj[j]">:
Matchkey = MatchingUserAs.get_or_insert(t2_obj[j].UserAId)
#the following if check has been added to avoid incrementing the counter
#when same UserAid is present in, say, t2_obj[0], and t2_obj[1], etc.
if(Matchkey.source != 'agegroup')
Matchkey.count = Matchkey.count + 1
Matchkey.source = 'agegroup'
Matchkey.put()
<"loop through t3_obj[j]">:
Matchkey = MatchingUserAs.get_or_insert(t3_obj[j].UserAId)
if(Matchkey.source != 'tags')
Matchkey.count = Matchkey.count + 1
Matchkey.source = 'tags'
Matchkey.put()