sonic-channel/README.md

113 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

2020-07-18 11:01:51 +03:00
# Sonic Channel
2022-07-21 10:04:29 +03:00
[![Build](https://github.com/pleshevskiy/sonic-channel/actions/workflows/ci.yml/badge.svg)](https://github.com/pleshevskiy/sonic-channel/actions/workflows/ci.yml)
2022-07-18 14:33:25 +03:00
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
[![Documentation](https://docs.rs/sonic-channel/badge.svg)](https://docs.rs/sonic-channel)
[![Crates.io](https://img.shields.io/crates/v/sonic-channel)](https://crates.io/crates/sonic-channel)
![Crates.io](https://img.shields.io/crates/l/sonic-channel)
2020-07-18 11:01:51 +03:00
Rust client for [sonic] search backend.
We recommend you start with the [documentation].
## Installation
2022-07-21 18:59:17 +03:00
**The MSRV is: 1.58.1**
2022-10-24 18:29:24 +03:00
Add `sonic-channel = { version = "1.1" }` 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-10-24 18:29:24 +03:00
sonic-channel = { version = "1.1", 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