sonic-channel/README.md

87 lines
1.9 KiB
Markdown
Raw Normal View History

2020-07-18 11:01:51 +03:00
# Sonic Channel
Rust client for [sonic] search backend.
We recommend you start with the [documentation].
## Installation
2022-07-04 11:47:33 +03:00
Add `sonic-channel = { version = "0.6" }` 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]
2022-07-04 11:47:33 +03:00
sonic-channel = { version = "0.6", features = ["ingest"] }
2020-07-18 11:01:51 +03:00
```
2022-07-04 11:47:33 +03:00
Add `default-features = false` to dependency, if you want to exclude default
`search` channel.
2020-07-18 11:01:51 +03:00
## Example usage
2020-07-18 11:36:31 +03:00
### Search channel
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::*;
fn main() -> result::Result<()> {
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
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::*;
fn main() -> result::Result<()> {
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<()> {
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
2022-03-23 23:34:33 +03:00
- **default** - ["search"]
- **search** - Add sonic search mode with methods
- **ingest** - Add sonic ingest mode with methods
- **control** - Add sonic control mode with methods
2020-07-18 11:01:51 +03:00
[sonic]: https://github.com/valeriansaliou/sonic
2020-07-26 23:43:08 +03:00
[documentation]: https://docs.rs/sonic-channel