sonic-channel/README.md

103 lines
2 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
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
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<()> {
2020-07-23 10:44:02 +03:00
let channel = SonicChannel::connect_with_start(
ChannelMode::Search,
2020-07-26 21:56:30 +03:00
"localhost:1491",
2020-07-23 10:44:02 +03:00
"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<()> {
2020-07-23 10:44:02 +03:00
let mut channel = SonicChannel::connect_with_start(
2020-07-26 21:56:30 +03:00
ChannelMode::Ingest,
2020-07-23 10:44:02 +03:00
"localhost:1491",
"SecretPassword",
)?;
2020-07-18 11:36:31 +03:00
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 mut channel = SonicChannel::connect_with_start(
ChannelMode::Control,
"localhost:1491",
"SecretPassword",
)?;
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