algoliasearch client go
v4.8.2
文件 • 社群論壇 • Stack Overflow • 回報錯誤 • 常見問題 • 支持
首先,透過 go get 指令安裝 Algolia API Go 客戶端:
go get github.com/algolia/algoliasearch-client-go/v4
現在您可以在專案中匯入 Algolia API 用戶端並使用它。
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client , err := search . NewClient ( "YOUR_APP_ID" , "YOUR_API_KEY" )
// Add a new record to your Algolia index
response , err := client . SaveObject ( client . NewApiSaveObjectRequest (
"<YOUR_INDEX_NAME>" , map [ string ] any { "objectID" : "id" , "test" : "val" },
))
if err != nil {
// handle the eventual error
panic ( err )
}
// use the model directly
print ( response )
// Poll the task status to know when it has been indexed
taskResponse , err := searchClient . WaitForTask ( "<YOUR_INDEX_NAME>" , response . TaskID , nil , nil , nil )
if err != nil {
panic ( err )
}
// Fetch search results, with typo tolerance
response , err := client . Search ( client . NewApiSearchRequest (
search . NewEmptySearchMethodParams (). SetRequests (
[]search. SearchQuery { * search . SearchForHitsAsSearchQuery (
search . NewEmptySearchForHits (). SetIndexName ( "<YOUR_INDEX_NAME>" ). SetQuery ( "<YOUR_QUERY>" ). SetHitsPerPage ( 50 ))}),
))
if err != nil {
// handle the eventual error
panic ( err )
}
// use the model directly
print ( response )
如需完整文檔,請造訪Algolia Go API 用戶端。
遇到問題?在尋求支援之前,我們建議您先查看我們的常見問題解答,您可以在其中找到最常見問題和客戶遇到的問題的答案。您也可以開啟 GitHub 問題
此儲存庫託管為 Go 產生的 Algolia API 用戶端的程式碼,如果您想做出貢獻,請前往主儲存庫。您也可以在我們的文件網站上找到貢獻指南。
Algolia Go API 用戶端是一款根據 MIT 授權授權的開源軟體。