sonic channel
v1.1.0
用於聲音搜尋後端的 Rust 用戶端。
我們建議您從文件開始。
MSRV 為:1.58.1
在Cargo.toml
中加入sonic-channel = { version = "1.1" }
作為依賴項。
Cargo.toml
範例:
[ package ]
name = " my-crate "
version = " 0.1.0 "
authors = [ " Me <[email protected]> " ]
[ dependencies ]
sonic-channel = { version = " 1.1 " , features = [ " ingest " ] }
如果要排除預設search
通道,請將default-features = false
新增至相依性。
注意:此範例需要啟用search
功能,預設啟用。
use sonic_channel :: * ;
fn main ( ) -> result :: Result < ( ) > {
let channel = SearchChannel :: start (
"localhost:1491" ,
"SecretPassword" ,
) ? ;
let objects = channel . query ( QueryRequest :: new (
Dest :: col_buc ( "collection" , "bucket" ) ,
"recipe" ,
) ) ? ;
dbg ! ( objects ) ;
Ok ( ( ) )
}
注意:此範例需要啟用ingest
功能。
use sonic_channel :: * ;
fn main ( ) -> result :: Result < ( ) > {
let channel = IngestChannel :: start (
"localhost:1491" ,
"SecretPassword" ,
) ? ;
let dest = Dest :: col_buc ( "collection" , "bucket" ) . obj ( "object:1" ) ;
let pushed = channel . push ( PushRequest :: new ( dest , "my best recipe" ) ) ? ;
// or
// let pushed = channel.push(
// PushRequest::new(dest, "Мой лучший рецепт").lang(Lang::Rus)
// )?;
dbg ! ( pushed ) ;
Ok ( ( ) )
}
注意:此範例需要啟用control
功能。
use sonic_channel :: * ;
fn main ( ) -> result :: Result < ( ) > {
let channel = ControlChannel :: start (
"localhost:1491" ,
"SecretPassword" ,
) ? ;
let result = channel . consolidate ( ) ? ;
assert_eq ! ( result, ( ) ) ;
Ok ( ( ) )
}