3

由于更高版本的远程 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')
4

1 回答 1

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 字符的文档上搜索带有片段字段的搜索失败。

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

于 2013-09-15T04:05:28.407 回答