本文整理匯總了Python中main.PageData.search_type方法的典型用法代碼示例。如果您正苦於以下問題:Python PageData.search_type方法的具體用法?Python PageData.search_type怎麽用?Python PageData.search_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類main.PageData
的用法示例。
在下文中一共展示了PageData.search_type方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: search
# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import search_type [as 別名]
def search():
"""
:URL: /item/search?page=<page>&type=<query type>&limit=<max results>&query=<search query>&sort=<sort type>
:Method: GET
:Query Types:
* item - Item Search
* user - User Search
:Sort Types:
* name - Alphabetical by name
* added - By added date, latest first
* modified - Last modified
:Sample Response: Setting the accept:application/json header will return JSON.
.. code-block:: javascript
{
"limit": 2,
"num_pages": 4,
"num_results": 8,
"query": "Cascadia",
"results": [
{
"added": "2016-05-22 17:52:36",
"body": "Blue/White (Cascadia Fringe, Gisele Currier Memorial Fundraiser)",
"description": 460,
"images": [
388,
389
],
"modified": "2016-05-24 22:45:33",
"name": "No Pity MLS Blue White Fringe (Cascadia Fringe) 2012",
"uid": 362
},
{
"added": "2016-05-22 17:02:15",
"body": "",
"description": 317,
"images": [
364,
365
],
"modified": "2016-05-22 17:02:15",
"name": "Cascadia",
"uid": 350
}
]
}
"""
pd = PageData()
pd.search_type = request.args.get('type')
pd.query = request.args.get('query')
pd.limit = request.args.get('limit')
pd.page = request.args.get('page')
pd.sort = request.args.get('sort')
try:
if not pd.limit:
pd.limit = 20
else:
pd.limit = int(pd.limit)
if not pd.page:
pd.page = 1
else:
pd.page = int(pd.page)
except ValueError:
return page_not_found()
if pd.search_type == "items":
return item_search(pd)
elif pd.search_type == "users":
return user_search(pd)
elif pd.search_type == "tags":
return tag_search(pd)
else:
pd.search_type = "items"
return item_search(pd)