我没有从 python 获得信息性跟踪,我只是收到一条消息InvalidRequest
,说明尽管我正在调查跟踪,但请求间歇性地工作。我得到的只是python说“InvalidRequest”,当我发现错误时,它只是说哪个搜索查询失败,如果我把它作为查询放在搜索框中,搜索查询就可以工作。因此,它是随机错误而不是超时是没有意义的,而且它根本无法帮助我将错误归类为 InvalidRequest。
可以做什么?
我问的没有解决问题的问题是
如果通过本网站上基于区域的列表向前翻页,并且在随后的重新加载(或第一次点击)中的第 2 或第 3 页看起来会因为超时错误而得到空结果,则可以找到问题的实时视图,但它不是超时。如果您到达分页的第 2 页然后按重新加载,那么它可能会在比超时更短的时间内失败或随机工作。
所以我需要帮助来了解发生了什么。我不明白我做错了什么。代码对我来说看起来不错,你觉得呢?
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 matching results by subject in descending order
sort = search.SortOptions(expressions=[date_desc, hr_desc,
min_desc], limit=ACCURACY)
# Set query options
options = search.QueryOptions(limit=50, cursor=cursor,
sort_options=sort, number_found_accuracy=10000,
# returned_fields=['title', 'city', 'region','category', 'adID', 'date','price', 'type', 'company_ad', 'adID', 'cityID','regionID', 'hour','minute'],
#snippeted_fields=['text']
)
query = search.Query(query_string=query_string, options=options)
index = search.Index(name=_INDEX_NAME)
logging.debug('query_string i find %s' , str(query.query_string))
logging.debug('query_options i find %s' , str(query.options))
# Execute the query
return index.search(query)
except search.PutError as e:
logging.exception('caught PutError %s', e)
except search.InternalError as e:
logging.exception('caught InternalError %s', e)
except search.DeleteError as e:
logging.exception('caught DeleteError %s', e)
except search.TransientError as e:
logging.exception('caught TransientError %s', e)
except search.InvalidRequest as e:
logging.exception('caught InvalidError %s', e)
except search.Error as e:
logging.exception('caught unknown error %s', e)
return None
完全删除排序会导致相同的错误:
def find_documents(query_string, limit, cursor):
try:
#date_desc = search.SortExpression(expression='date',
direction=search.SortExpression.DESCENDING,
default_value=datetime(2013,01,01))
#hr_desc = search.SortExpression(expression='hour',
direction=search.SortExpression.DESCENDING,
default_value=1)
#min_desc = search.SortExpression(expression='minute',
direction=search.SortExpression.DESCENDING,
default_value=1)
# Sort up to matching results by subject in descending order
#sort = search.SortOptions(expressions=[date_desc, hr_desc,
min_desc], limit=ACCURACY)
# Set query options
options = search.QueryOptions(limit=50, cursor=cursor,
#sort_options=sort,
number_found_accuracy=10000,
# returned_fields=['title', 'city', 'region','category', 'adID', 'date','price', 'type', 'company_ad', 'adID', 'cityID','regionID', 'hour','minute'],
#snippeted_fields=['text']
)
query = search.Query(query_string=query_string, options=options)
index = search.Index(name=_INDEX_NAME)
logging.debug('query_string i find %s' , str(query.query_string))
logging.debug('query_options i find %s' , str(query.options))
# Execute the query
return index.search(query)