2020-07-18 11:01:51 +03:00
|
|
|
# Sonic Channel
|
|
|
|
|
|
|
|
Rust client for [sonic] search backend.
|
|
|
|
|
|
|
|
We recommend you start with the [documentation].
|
|
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2020-08-07 02:58:19 +03:00
|
|
|
Add `sonic-channel = { version = "0.3" }` as a dependency in `Cargo.toml`.
|
2020-07-18 11:01:51 +03:00
|
|
|
|
|
|
|
`Cargo.toml` example:
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[package]
|
|
|
|
name = "my-crate"
|
2020-08-07 02:58:19 +03:00
|
|
|
version = "0.1.0"
|
2020-07-18 11:01:51 +03:00
|
|
|
authors = ["Me <user@rust-lang.org>"]
|
|
|
|
|
|
|
|
[dependencies]
|
2020-08-07 02:58:19 +03:00
|
|
|
sonic-channel = { version = "0.3" }
|
2020-07-18 11:01:51 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Example usage
|
|
|
|
|
2020-07-18 11:36:31 +03:00
|
|
|
### Search channel
|
|
|
|
|
2020-07-31 23:34:58 +03:00
|
|
|
Note: This example requires enabling the `search` feature, enabled by default.
|
|
|
|
|
2020-07-18 11:01:51 +03:00
|
|
|
```rust
|
2020-07-18 11:36:31 +03:00
|
|
|
use sonic_channel::*;
|
|
|
|
|
2020-07-19 10:17:53 +03:00
|
|
|
fn main() -> result::Result<()> {
|
2020-11-25 19:09:08 +03:00
|
|
|
let channel = SearchChannel::start("localhost:1491", "SecretPassword")?;
|
2020-07-18 11:36:31 +03:00
|
|
|
let objects = channel.query("collection", "bucket", "recipe")?;
|
|
|
|
dbg!(objects);
|
2020-07-18 11:01:51 +03:00
|
|
|
|
2020-07-18 11:36:31 +03:00
|
|
|
Ok(())
|
2020-07-18 11:01:51 +03:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-07-18 11:36:31 +03:00
|
|
|
### Ingest channel
|
2020-07-18 11:01:51 +03:00
|
|
|
|
2020-07-31 23:34:58 +03:00
|
|
|
Note: This example requires enabling the `ingest` feature.
|
|
|
|
|
2020-07-18 11:01:51 +03:00
|
|
|
```rust
|
2020-07-18 11:36:31 +03:00
|
|
|
use sonic_channel::*;
|
|
|
|
|
2020-07-19 10:17:53 +03:00
|
|
|
fn main() -> result::Result<()> {
|
2020-11-25 19:09:08 +03:00
|
|
|
let channel = IngestChannel::start("localhost:1491", "SecretPassword")?;
|
2020-07-26 21:56:30 +03:00
|
|
|
let pushed = channel.push("collection", "bucket", "object:1", "my best recipe")?;
|
2020-07-23 10:44:02 +03:00
|
|
|
// or
|
2020-07-26 21:56:30 +03:00
|
|
|
// let pushed = channel.push_with_locale("collection", "bucket", "object:1", "Мой лучший рецепт", "rus")?;
|
2020-07-18 11:36:31 +03:00
|
|
|
dbg!(pushed);
|
|
|
|
|
|
|
|
Ok(())
|
2020-07-18 11:01:51 +03:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-08-07 02:58:19 +03:00
|
|
|
### Control channel
|
|
|
|
|
|
|
|
Note: This example requires enabling the `control` feature.
|
|
|
|
|
|
|
|
```rust
|
|
|
|
use sonic_channel::*;
|
|
|
|
|
|
|
|
fn main() -> result::Result<()> {
|
2020-11-25 19:09:08 +03:00
|
|
|
let channel = ControlChannel::start("localhost:1491", "SecretPassword")?;
|
2020-08-07 02:58:19 +03:00
|
|
|
let result = channel.consolidate()?;
|
|
|
|
assert_eq!(result, true);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-07-18 11:01:51 +03:00
|
|
|
|
|
|
|
## Available features
|
|
|
|
|
|
|
|
* **default** - ["search"]
|
|
|
|
* **search** - Add sonic search mode with methods
|
|
|
|
* **ignite** - Add sonic ignite mode with methods
|
|
|
|
* **control** - Add sonic control mode with methods
|
|
|
|
|
|
|
|
|
|
|
|
[sonic]: https://github.com/valeriansaliou/sonic
|
2020-07-26 23:43:08 +03:00
|
|
|
[documentation]: https://docs.rs/sonic-channel
|