2014-04-17 42 views
2

我构建了一个数据库,我希望能够使用GAE中的Search API进行搜索。我点击了Google上关于API的教程,但我缺少的一件事是如何将数据存储类型转换为“文档”。有什么好的教程吗?谢谢如何在我的GAE数据存储上实现搜索API?

+1

编写的代码拷贝属性值从数据存储实体到搜索API文档。 –

回答

3

db.Model ndb.Model不能转换为search.Document。

为什么?因为它没有太多的价值。

我给你一些例子 - 你有字符串“这-是黑标签”在db.StringProperty()如何将它转换:

  1. 你可以使用它作为原子 - 所以比赛将是如果完全匹配
  2. 您可以将其用作字符串 - 因此它会被分成'this','is','black','tag',而不是标记为't','th','thi','this ” ...
  3. 您可以决定是不可见的,因为在搜索忍不住给虚假点击

您需要自己设计搜索功能,它应该是手动设计,即答案

你只需要:

  1. 创建search.Document
  2. 添加字段
  3. 添加文档索引

阅读参考:https://developers.google.com/appengine/docs/python/search/documentclass

0

不幸的是,这是不可能的。

看看索引构造函数(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提交功能请求,并在那里发送。

0

我有成千上万的实体,我想建立一个索引,然后使用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))