Aloha!又是我少女人妻 Uerica!連假結束的好快阿!月餅柚子都還沒吃夠欸!對了不可以讓毛小孩帶柚子皮喔~柚子皮成分對毛孩有毒!會引發過敏喔!QQ
終於進入 App Search 的 API 應用拉!讓我們開始吧~
Search API 用於資料搜尋、篩選過濾、策展等
Search API 可以用的 Method 有 GET
跟 POST
,可以查詢兩種不同的 endpoints
兩者不同的是 multi_search 在一個 API 調用中最多允許 10 個查詢
query
搜尋相關資料的字串或數字,要搜尋所有資料,需使用空字串 "" 。還可以應用詢語法函數 : 雙引號字串,+和-,AND,OR和NOT。
page
指定搜尋大小和指定當前頁面。
單字詞搜尋
POST /{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search
GET /{API Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search
Authorization 要用 Bearer Token,值是 Credentials 的 search-key
curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-xxxxxxxxxx' \
-d '{
"query": "花蓮"
}'
回傳結果,會帶有 page、engine、request_id 以及 results 等資訊
{
"meta": {
"alerts": [],
"warnings": [],
"page": {
"current": 1,
"total_pages": 1,
"total_results": 5,
"size": 10
},
"engine": {
"name": "6gogo",
"type": "default"
},
"request_id": "a1f64616-1e3a-4aed-9f32-999f564020ae"
},
"results": [
{
"place_desc": {
"raw": "馬太鞍溼地是一處綠意盎然的自然樂園,由南向北蜿蜒穿過馬太鞍溼地的芙登溪,滋養了這片沼澤的豐美生態。沿著涓涓小溪騎乘單車,任何一條水溝,都可以發現魚、蝦、貝、螺的蹤跡,充滿旺盛生機。"
},
"_meta": {
"engine": "6gogo",
"id": "13",
"score": 8.50604
},
"note": {
"raw": null
},
"phone": {
"raw": "038700015"
},
"id": {
"raw": "13"
},
"area": {
"raw": "光復鄉"
},
"place_name": {
"raw": "馬太鞍溼地生態館"
}
},
...
]
}
使用AND、OR、NOT語法執行查詢
curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-xxxxxxxxxx' \
-d '{
"query": "花蓮 AND 吉安鄉 OR 光復鄉 NOT 壽豐鄉"
}'
執行多字詞搜尋
curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/multi_search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-xxxxxxxxxx' \
-d '{
"queries": [
{"query": "花蓮縣"},
{"query": "光復鄉"}
]
}'
Page
對分頁進行調整
例如剛剛"query": "花蓮"
的結果,總共有4頁32筆資料(預設一頁10筆),如果我只想要一頁2筆資料,並回傳第2頁結果
curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-xxxxxxxxxx' \
-d '{
"query": "花蓮",
"page": {
"size": 2,
"current": 2
}
}'
回傳結果
{
"meta": {
"alerts": [],
"warnings": [],
"page": {
"current": 2,
"total_pages": 16,
"total_results": 32,
"size": 2
},
"engine": {
"name": "6gogo",
"type": "default"
},
"request_id": "f96d0ea5-99a4-441d-a093-d14a31c8aed1"
},
"results": [
{
"place_desc": {
"raw": [
"靠海的寵物友善民宿",
"從民宿可直接走到海岸",
"園內整天提供茶點",
"水果",
"還有KTV設施",
"也是看日出的好位置"
]
},
"_meta": {
"engine": "6gogo",
"id": "18",
"score": 0.11712785
},
"note": {
"raw": null
},
"phone": {
"raw": "038671236"
},
"id": {
"raw": "18"
},
"area": {
"raw": "壽豐鄉"
},
"place_name": {
"raw": "花蓮海中天民宿"
}
},
{
"place_desc": {
"raw": "米噹泰式烤肉,位於一樓的開放式店面氣氛很像台北的熱炒店一樣,不過賣的都是好吃又重口味的類泰式料理,每一道菜都可以扒好幾碗飯!而且份量十足!有時對面店家的黃金還會來討東西吃,如果有帶狗只需繫牽繩即可,如果狗狗怕生可以請店員安排較角落的位置"
},
"_meta": {
"engine": "6gogo",
"id": "29",
"score": 0.0963902
},
"note": {
"raw": null
},
"phone": {
"raw": "038357031"
},
"id": {
"raw": "29"
},
"area": {
"raw": "花蓮市"
},
"place_name": {
"raw": "米噹泰式烤肉"
}
}
]
}
常見 Error
今天就到這邊拉~感謝各為閱讀!除了不可以給毛孩帶柚子皮,還要小心他們偷吃烤肉喔,哈哈哈,明天見拉掰掰!