App Engine 1.8.4引发AttributeError将文档放入搜索索引

时间:2013-09-14 22:52:27

标签: python google-app-engine gae-search

由于远程API在更高版本中存在已知问题,我一直在使用1.8.1版本的App Engine API。尝试使用最新的1.8.4,我遇到了错误,代码在1.8.1中工作正常,但现在无法尝试将文档添加到搜索索引中:

Traceback (most recent call last):
   File "~/tools/devappserver2/api_server.py", 
62, in _handle_POST
    api_response = _execute_request(request).Encode()
  File "~/tools/devappserver2/api_server.py", line 1
23, in _execute_request
    make_request()
  File "~/tools/devappserver2/api_server.py", line 1
15, in make_request
    request_id)
  File "~/google/appengine/api/apiproxy_stub.py", line 130, in MakeSy
ncCall
    method(request, response)
  File "~/google/appengine/api/search/simple_search_stub.py", line 65
4, in _Dynamic_IndexDocument
    index.IndexDocuments(params.document_list(), response)
  File "~/google/appengine/api/search/simple_search_stub.py", line 40
4, in IndexDocuments
    self._inverted_index.AddDocument(doc_id, document)
  File "~/google/appengine/api/search/simple_search_stub.py", line 30
3, in AddDocument
    self._AddFieldType(field.name(), field.value().type())
  File "~/google/appengine/api/search/simple_search_stub.py", line 28
9, in _AddFieldType
    self._schema.AddFieldType(name, field_type)
AttributeError: 'dict' object has no attribute 'AddFieldType'

ERROR    2013-09-14 22:31:45,132 webapp2.py:1552] AttributeError("'dict' object has no attribute 'Ad
dFieldType'",)
Traceback (most recent call last):
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispat
cher
    return route.handler_adapter(request, response)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "~/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "~/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "~/docroot/update.py", line 49, in get
    booking.add_to_search_index()
  File "~/docroot/booking.py", line 94, in add_to_search_index
    index.put(booking_full_text_document)
  File "~/google/appengine/api/search/search.py", line 2506, in put
    response)
  File "~/google/appengine/api/apiproxy_stub_map.py", line 94, in Mak
eSyncCall
    return stubmap.MakeSyncCall(service, call, request, response)
  File "~/google/appengine/api/apiproxy_stub_map.py", line 328, in Ma
keSyncCall
    rpc.CheckSuccess()
  File "~/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitIm
pl
    self.request, self.response)
  File "~/google/appengine/ext/remote_api/remote_api_stub.py", line 2
00, in MakeSyncCall
    self._MakeRealSyncCall(service, call, request, response)
  File "~/google/appengine/ext/remote_api/remote_api_stub.py", line 2
34, in _MakeRealSyncCall
    raise pickle.loads(response_pb.exception())
RuntimeError: AttributeError("'dict' object has no attribute 'AddFieldType'",)
INFO     2013-09-14 22:31:45,145 module.py:593] default: "GET /update/somekey/someparamter/value HTTP/1.1" 500 2
691

负责的代码部分:

from google.appengine.ext import ndb
from google.appengine.api import search
import logging

class Booking(ndb.Model):

    timestamp = ndb.DateTimeProperty(auto_now_add=True)
    last_modified = ndb.DateTimeProperty(auto_now=True)

    field1 = ndb.StringProperty()
    field2 = ndb.StringProperty()
    #etc...

    def add_to_search_index(self):

        list_of_full_text_fields = [
            'field1',
            'field2',
        ]

        full_text_data = []

        for field in list_of_full_text_fields:

            full_text_data.append(unicode(getattr(self, field)))

        full_text_data = ' '.join(full_text_data)

        full_text_document = search.Document(

        doc_id = self.key.urlsafe(),
        fields=[
            search.TextField(
                name='f',
                value=full_text_data
            ),
           ]
        )

        try:
            index = search.Index(name="fullText")
            index.put(full_text_document)
        except search.Error:
            logging.exception('Put failed')

1 个答案:

答案 0 :(得分:2)

可能是那些版本的API更改吗?

版本1.8.3 - 2013年8月6日 发布了Search API文档的重大改写。请参阅:https://developers.google.com/appengine/docs/python/search/

或错误修正..

版本1.8.4 - 2013年9月9日 修复了与Search API中的表达式相关联的unicode问题。对于包含unicode字符的文档,使用snippeted字段进行搜索失败。

http://code.google.com/p/googleappengine/wiki/SdkReleaseNotes