Search failed
Traceback (most recent call last):
File "/base/data/home/apps/s~montaoproject/2013e.368508855356793432/search_demo.py", line 87, in find_documents
return index.search(query)
File "/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 2732, in search
_CheckStatus(response.status())
File "/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 413, in _CheckStatus
raise _ERROR_MAP[status.code()](status.error_detail())
InvalidRequest: Failed to execute search request ""
代码
def find_documents(query_string, limit, cursor):
try:
date_desc = search.SortExpression(expression='date',
direction=search.SortExpression.DESCENDING,
default_value=datetime.now().date())
hr_desc = search.SortExpression(expression='hour',
direction=search.SortExpression.DESCENDING,
default_value=datetime.now().hour)
min_desc = search.SortExpression(expression='minute',
direction=search.SortExpression.DESCENDING,
default_value=datetime.now().minute)
# Sort up to 5000 matching results by subject in descending order
sort = search.SortOptions(expressions=[date_desc, hr_desc,
min_desc], limit=10000)
# Set query options
options = search.QueryOptions(limit=limit, cursor=cursor,
sort_options=sort, number_found_accuracy=10000) # the number of results to return
# returned_fields=['author', 'subject', 'summary'],
# snippeted_fields=['content']
query = search.Query(query_string=query_string, options=options)
index = search.Index(name=_INDEX_NAME)
# Execute the query
return index.search(query)
except search.Error:
logging.exception('Search failed')
return None
class USA(SearchBaseHandler):
def get(self):
"""Handles a get request with a query."""
regionname = 'New York'
region = Region.all().filter('name = ', regionname).get()
cursor = self.request.get('cursor')
uri = urlparse(self.request.uri)
query = ''
if uri.query:
query = parse_qs(uri.query)
try:
query = query['query'][0]
except KeyError, err:
query = ''
# logging.info('KeyError')
# logging.info('search cursor: %s', search.Cursor())
if cursor:
results = find_documents(query, 50, search.Cursor(cursor))
else:
results = find_documents(query, 50, search.Cursor())
next_cursor = None
if results and results.cursor:
next_cursor = results.cursor.web_safe_string
query = query.replace(' and company_ad=0', ''
).replace(' and company_ad=1', '')
# logging.info('next cursor: %s', str(next_cursor))
template_values = {
'results': results,
'cursor': next_cursor,
'number_returned': len(results.results),
'user': users.get_current_user(),
'loggedin': self.logged_in,
'region': region,
'regionname': regionname,
'city': '',
'cityentity': None,
'request': self.request,
'form': SearchForm(),
'query': query,
}
self.render_template('q.htm', template_values)
更新
有效的第 2 页链接如下所示
q?query=regionID%3D4702187&cursor=False:CqoECuYBCtgB_wDAQM7xgAD_AP8A_wD__wDAQCQA_wD_AP8A_wD_AP__AMBAPwD_AP8A_wD_AP8A___-9wlMHAj_jv9jjIGSkJGLnpCPjZCVmpyL_wB0baCgmYuMoKD_AF2ej4-akZiWkZr_AHN0bZaRm5qH_wBdnpuM_wBzdG2bkJyglpv_AF2emMaFmZLOiZ2RrZedzL2Gnc2Pk6bMrYa8iIysvpS5lLi1vMaRiLKy_wBzf56YxoWZks6JnZGtl53MvYadzY-TpsythryIjKy-lLmUuLW8xpGIsrL_AP_-EDIh4o_3av1KJSkSDURvY3VtZW50SW5kZXganwEoQU5EIChJUyAiY3VzdG9tZXJfbmFtZSIgImFwcGVuZ2luZSIpIChJUyAiZ3JvdXBfbmFtZSIgInN-bW9udGFvcHJvamVjdCIpIChJUyAibmFtZXNwYWNlIiAiIikgKElTICJpbmRleF9uYW1lIiAiYWRzIikgKEVRIDQ3MDIxODcuMDAwMDAwMDAwMDAgInNuYnJfcmVnaW9uSUQiKSk6GwoOKE4gc2RhdGVfZGF0ZSkQARkAAEANwvpzQjoaCg0oTiBzbmJyX2hvdXIpEAEZAAAAAAAAKEA6HAoPKE4gc25icl9taW51dGUpEAEZAAAAAACASUBKHAgBOhVzdDpidGlfZ2VuZXJpY19zY29yZXJAkE5SGQoMKE4gb3JkZXJfaWQpEAEZAAAAAAAA8P8
我会尝试看看我是否可以让它随机失败,然后我们就会知道这是一个超时错误。如果这是一个超时错误,那么我可以使用 memcache 缓存它并进行一些成本较低的调用以避免往返,它会起作用(?)
我正在为空白查询和基于 reiog 的搜索执行此操作,其中我将搜索限制在上述区域,并且 regionID 是索引文档的一个字段。您可以查看 [live site][1] 来查看操作。
更新 2
有效的第 2 页链接如下所示
/q?query=&cursor=False:CocECuYBCtgB_wDAQM8JAP8A_wD_AP8A__8AwEAkAP8A_wD_AP8A_wD__wDAQECAAP8A_wD_AP8A___-9wltwdL_Iv_jjIGSkJGLnpCPjZCVmpyL_wB0baCgmYuMoKD_AF2ej4-akZiWkZr_AHN0bZaRm5qH_wBdnpuM_wBzdG2bkJyglpv_AF2emMaFmZLOiZ2RrZedzL2Gnc2Pk6bMrYa8iIysvpS5lLi2vJXLrrKy_wBzf56YxoWZks6JnZGtl53MvYadzY-TpsythryIjKy-lLmUuLa8lcuusrL_AP_-EDIh4o_3av1KJSkSDURvY3VtZW50SW5kZXgafShBTkQgKElTICJjdXN0b21lcl9uYW1lIiAiYXBwZW5naW5lIikgKElTICJncm91cF9uYW1lIiAic35tb250YW9wcm9qZWN0IikgKElTICJuYW1lc3BhY2UiICIiKSAoSVMgImluZGV4X25hbWUiICJhZHMiKSAoVFJVRSkpOhsKDihOIHNkYXRlX2RhdGUpEAEZAABADcL6c0I6GgoNKE4gc25icl9ob3VyKRABGQAAAAAAACxAOhwKDyhOIHNuYnJfbWludXRlKRABGQAAAAAAgElAShwIAToVc3Q6YnRpX2dlbmVyaWNfc2NvcmVyQJBOUhkKDChOIG9yZGVyX2lkKRABGQAAAAAAAPD_
如果我按重新加载它可以工作或失败,所以它看起来像一个随机错误。有任何想法吗?