1

我在 GAE 搜索 api 中使用“snippeted_fields”来搜索产品描述。

这是搜索索引表中的产品描述:Multirate 10G IP Services Engine (Modular)+Phone。我正在寻找Multirate 10G IP。apppot中没有错误。但是 dev_appserver 返回以下错误。

ERROR    2012-10-03 04:22:40,497 functions.py:143] local variable 'prev_len' referenced before assignment
Traceback (most recent call last):
   File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1530, in __call__
     rv = self.router.dispatch(request, response)
   File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1278, in default_dispatcher
     return route.handler_adapter(request, response)
   File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1102, in __call__
     return handler.dispatch()
   File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch
     return self.handle_exception(e, self.app.debug)
   File "C:\Program Files\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch
     return method(*args, **kwargs)
   File "C:\Users\app_search\search.py", line 1664, in get
     result = find_search_document(search_item)
   File "C:\Users\app_search\search.py", line 192, in find_search_document
     result = index.search(query_string)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\search\search.py", line 2722, in search
     apiproxy_stub_map.MakeSyncCall('search', 'Search', request, response)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 94, in MakeSyncCall
     return stubmap.MakeSyncCall(service, call, request, response)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 320, in MakeSyncCall
     rpc.CheckSuccess()
   File "C:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_rpc.py", line 156, in _WaitImpl
     self.request, self.response)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_stub.py", line 160, in MakeSyncCall
    method(request, response)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\search\simple_search_stub.py", line 871, in _Dynamic_Search
     results = index.Search(params)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\search\simple_search_stub.py", line 510, in Search
     docs = self._AttachExpressions(docs, search_request)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\search\simple_search_stub.py", line 493, in _AttachExpressions
     evaluator.Evaluate(expr)
   File "C:\Program Files\Google\google_appengine\google\appengine\api\search\stub\expression_evaluator.py", line 198, in Evaluate
    result = self._Eval(expression_tree)
  File "C:\Program Files\Google\google_appengine\google\appengine\api\search\stub\expression_evaluator.py", line 156, in _Eval
    return func(*node.children)
  File "C:\Program Files\Google\google_appengine\google\appengine\api\search\stub\expression_evaluator.py", line 132, in _Snippet
    doc_words, position, search_util.DEFAULT_MAX_SNIPPET_LENGTH)
  File "C:\Program Files\Google\google_appengine\google\appengine\api\search\stub\expression_evaluator.py", line 95, in _GenerateSnippet
    while (len(snippet) + next_len + prev_len + 6 < max_length and
UnboundLocalError: local variable 'prev_len' referenced before assignment

代码:

def find_search_document(query):
   _INDEX_NAME = "GPL_Description"    
   query = '"{0}"'.format(query.replace('"',''))

   options = search.QueryOptions(           
        snippeted_fields=['description'])

   query_string = search.Query(query_string = query, options = options)

   index = search.Index(name=_INDEX_NAME)
   return index.search(query_string)

另外,是否可以使用搜索 api 突出显示“多速率 10G IP 服务引擎”等小型描述的搜索查询?

4

1 回答 1

2

IIRC snippeted_fields在开发服务器上不起作用。

尝试部署它并检查行为,它应该在部署时按预期工作。

尽管根据我的经验,它只是在开发服务器上没有返回任何结果,而不是上面的错误。

于 2012-10-03T10:19:01.307 回答