本文整理汇总了Python中autocompleter.Autocompleter.get_results方法的典型用法代码示例。如果您正苦于以下问题:Python Autocompleter.get_results方法的具体用法?Python Autocompleter.get_results怎么用?Python Autocompleter.get_results使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autocompleter.Autocompleter
的用法示例。
在下文中一共展示了Autocompleter.get_results方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import get_results [as 别名]
def get(self):
# logging.info("request start \n{}".format(time.clock() * 1000 % 1000))
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
query = self.request.get('q')
logging.info(u"Autocomplete search for '{}'".format(query))
autocompleter = Autocompleter()
# logging.info("before autocompleter.get_results \n{}".format(time.clock() * 1000 % 1000))
results = autocompleter.get_results(query)
# logging.info("after autocompleter.get_results \n{}".format(time.clock() * 1000 % 1000))
json_results = []
for book in results:
if book is None:
logging.warning(u"Autocompleter result for '{}' returned None."
.format(query))
continue
assert isinstance(book, BookRecord)
suggestion_map = {'author': book.author, 'title': book.title,
'year': book.year, 'count': book.count,
'item_ids': book.key.string_id()}
json_results.append(suggestion_map)
json_object = {
'query': query,
'version': AutocompleteJson.CURRENT_VERSION,
'status': 'completed',
'suggestions': json_results
}
# logging.info("before json.dump \n{}".format(time.clock() * 1000 % 1000))
self.response.write(json.dumps(json_object, indent=2))
示例2: get
# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import get_results [as 别名]
def get(self):
result = u"<p>Behold autocomplete stuff:</p>"
autocompleter = Autocompleter()
query = self.request.get('q', default_value=u"Tolkien")
suggestions = autocompleter.get_results(query)
result += u"<pre>"
for suggestion in suggestions:
assert isinstance(suggestion, BookRecord)
result += u"{} - {} ({})\n".format(suggestion.author, suggestion.title, suggestion.year)
result += u"</pre>"
render_html(self, "admin_generic.html", u"Testing BQ",
result)