[英]How to implement the Search API on my GAE datastore?
我建立了一个数据库,希望能够使用GAE中的Search API进行搜索。 我单击了Google在API上的教程,但是我所缺少的一件事是如何将数据存储类型实际转换为“文档”。 在某个地方有一个好的教程吗? 谢谢
您不能将db.Model ndb.Model转换为search.Document。
为什么? 因为它没有太多价值。
我给你举个例子-db.StringProperty()中的字符串'this-is-black-tag'如何转换:
您需要自己的设计搜索功能,它应该是答案的手动设计 。
您只需要:
阅读参考资料: https : //developers.google.com/appengine/docs/python/search/documentclass
不幸的是,这是不可能的。
查看Index构造函数(python),我们可以发现有一些尝试可以在早期阶段实现它,但实际上并没有奏效。 指定索引的来源已经过了一阵子了,现在不再起作用了。
这是构造函数pydoc:
class Index(object):
[...]
def __init__(self, name, namespace=None, source=SEARCH):
"""Initializer.
Args:
name: The name of the index. An index name must be a visible printable
ASCII string not starting with '!'. Whitespace characters are excluded.
namespace: The namespace of the index name. If not set, then the current
namespace is used.
source: Deprecated as of 1.7.6. The source of
the index:
SEARCH - The Index was created by adding documents throught this
search API.
DATASTORE - The Index was created as a side-effect of putting entities
into Datastore.
CLOUD_STORAGE - The Index was created as a side-effect of adding
objects into a Cloud Storage bucket.
[...]
"""
因此,至少就目前而言(?),唯一的解决方案(如Tim Hoffman所述 )是将文档和索引与数据存储区数据分开处理。
您仍然可以向https://code.google.com/p/googleappengine/issues/list ans提出功能请求。
我有成千上万个实体,我想为其建立索引,然后使用mapreduce为我的实体建立索引,并且可以使用搜索API进行搜索。 mapreduce工作是
- name: buildindex
mapper:
input_reader: mapreduce.input_readers.DatastoreInputReader
handler: main.buildindex
params:
- name: entity_kind
default: main.Article
功能
def buildindex(entity):
try:
doc = search.Document(doc_id=str(entity.key()), fields=[
search.TextField(name='title', value=entity.title),
search.TextField(name='text', value=entity.text),
])
search.Index(name='myIndex').put(doc)
except Exception, e:
logging.exception('Mapreduce has exception:%s' % str(e))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.