sonic-channel/README.md

105 lines
2.1 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]
sonic-channel = { version = "1.0", 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",
)?;
let objects = channel.query(QueryRequest::new(
Dest::col_buc("collection", "bucket"),
"recipe",
))?;
2020-07-18 11:36:31 +03:00
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",
)?;
let dest = Dest::col_buc("collection", "bucket").obj("object:1");
let pushed = channel.push(PushRequest::new(dest, "my best recipe"))?;
2020-07-23 10:44:02 +03:00
// or
// let pushed = channel.push(
// PushRequest::new(dest, "Мой лучший рецепт").lang(Lang::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, ());
2020-08-07 02:58:19 +03:00
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