Google App Engine - 使用Search API Python列表字段 [英] Google App Engine - Using Search API Python with list fields
本文介绍了Google App Engine - 使用Search API Python列表字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用ndb.Model。
Search API包含以下字段类:
TextField:纯文本
HtmlField:HTML格式的文本
AtomField:一个被视为单个标记的字符串
NumberField:一个数值(float或integer)
DateField:没有时间分量的日期
GeoField:locale基于经度和纬度
假设我有一个'tags'字段,它是一个列表字段: p>
tags = ndb.StringProperty(repeated = True)
我应该如何用 search.Document
?
<现在我将
tags
列表变成一个字符串: t ='|'.join(tags)
然后:
search.TextField(name = cls.TAGS,value = t)
有什么建议?
解决案
使用唯一标识符对于每个 标签。然后你可以创建一个文件,如:
doc = search.Document(fields = [
search.TextField(name ='tags',value ='tag1 tag2 tag3'),
])
search.Index(name ='tags')。put(doc)
甚至可以使用数字(id)作为字符串:
doc = search.Document(fields = [
search.TextField(name ='tags',value ='123 456 789'),
])
$ c $<$ c $
使用运算符进行查询: (标签:((标签1和标签2)或(标签3和标签4))')
I'm using ndb.Model. The Search API has the following field classes:
TextField : plain text HtmlField : HTML formatted text AtomField : a string which is treated as a single token NumberField : a numeric value (either float or integer) DateField : a date with no time component GeoField : a locale based on latitude and longitude
Suppose I have a 'tags' field which is a list field:
tags = ndb.StringProperty(repeated=True)
How am I supposed to treat this field with
search.Document
?Right now I'm turning
tags
list into a string:t = '|'.join(tags)
And then:
search.TextField(name=cls.TAGS, value=t)
Any suggestions?
解决方案Use unique identifiers for each "tag". Then you can create a document like:
doc = search.Document(fields=[ search.TextField(name='tags', value='tag1 tag2 tag3'), ]) search.Index(name='tags').put(doc)
You can even use numbers (ids) as strings:
doc = search.Document(fields=[ search.TextField(name='tags', value='123 456 789'), ])
And query using operators as you wish:
index = search.Index(name='tags') results = index.search('tags:(("tag1" AND "tag2") OR ("tag3" AND "tag4"))')
这篇关于Google App Engine - 使用Search API Python列表字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文