doc: add examples for all sonic method

This commit is contained in:
Dmitriy Pleshevskiy 2020-08-01 23:34:28 +03:00
parent 4875bffb4c
commit 85ddd8fb4e

View file

@ -225,7 +225,7 @@ impl SonicChannel {
let channel = SonicChannel::connect_with_start(
ChannelMode::Search,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
channel.quit()?;
@ -243,7 +243,7 @@ impl SonicChannel {
let channel = SonicChannel::connect_with_start(
ChannelMode::Search,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
channel.ping()?;
@ -267,14 +267,14 @@ impl SonicChannel {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Ingest,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
let result = ingest_channel.push(
"search",
"default",
"recipe:295",
"Sweet Teriyaki Beef Skewers"
"Sweet Teriyaki Beef Skewers",
)?;
assert_eq!(result, true);
# Ok(())
@ -300,7 +300,7 @@ impl SonicChannel {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Ingest,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
let result = ingest_channel.push_with_locale(
@ -308,14 +308,13 @@ impl SonicChannel {
"default",
"recipe:296",
"Гренки с жареным картофелем и сыром",
"rus"
"rus",
)?;
assert_eq!(result, true);
# Ok(())
# }
```
"#]
#[doc=""]
use PushCommand for fn push_with_locale<'a>(
collection: &'a str,
bucket: &'a str,
@ -336,7 +335,7 @@ impl SonicChannel {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Ingest,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
let result = ingest_channel.pop("search", "default", "recipe:295", "beef")?;
@ -364,7 +363,7 @@ impl SonicChannel {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Ingest,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
let flushc_count = ingest_channel.flushc("search")?;
@ -389,7 +388,7 @@ impl SonicChannel {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Ingest,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
let flushb_count = ingest_channel.flushb("search", "default")?;
@ -415,7 +414,7 @@ impl SonicChannel {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Ingest,
"localhost:1491",
"SecretPassword"
"SecretPassword",
)?;
let flusho_count = ingest_channel.flusho("search", "default", "recipe:296")?;
@ -433,14 +432,60 @@ impl SonicChannel {
#[cfg(feature = "search")]
init_commands! {
#[doc="Query objects in database."]
#[doc=r#"
Query objects in database.
Note: This method requires enabling the `search` feature and start
connection in Search mode.
```rust,no_run
# use sonic_channel::*;
# fn main() -> result::Result<()> {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Search,
"localhost:1491",
"SecretPassword",
)?;
let result = ingest_channel.query("search", "default", "Beef")?;
dbg!(result);
# Ok(())
# }
```
"#]
use QueryCommand for fn query<'a>(
collection: &'a str,
bucket: &'a str,
terms: &'a str,
);
#[doc="Query limited objects in database."]
#[doc=r#"
Query limited objects in database. This method similar query but
you can configure limit of result.
Note: This method requires enabling the `search` feature and start
connection in Search mode.
```rust,no_run
# use sonic_channel::*;
# fn main() -> result::Result<()> {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Search,
"localhost:1491",
"SecretPassword",
)?;
let result = ingest_channel.query_with_limit(
"search",
"default",
"Beef",
10,
)?;
dbg!(result);
# Ok(())
# }
```
"#]
use QueryCommand for fn query_with_limit<'a>(
collection: &'a str,
bucket: &'a str,
@ -448,7 +493,34 @@ impl SonicChannel {
limit: usize => Some(limit),
);
#[doc="Query limited objects with offset in database."]
#[doc=r#"
Query limited objects in database. This method similar
query_with_limit but you can put offset in your query.
Note: This method requires enabling the `search` feature and start
connection in Search mode.
```rust,no_run
# use sonic_channel::*;
# fn main() -> result::Result<()> {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Search,
"localhost:1491",
"SecretPassword",
)?;
let result = ingest_channel.query_with_limit_and_offset(
"search",
"default",
"Beef",
10,
10,
)?;
dbg!(result);
# Ok(())
# }
```
"#]
use QueryCommand for fn query_with_limit_and_offset<'a>(
collection: &'a str,
bucket: &'a str,
@ -457,14 +529,55 @@ impl SonicChannel {
offset: usize => Some(offset),
);
#[doc="Suggest auto-completes words."]
#[doc=r#"
Suggest auto-completes words.
Note: This method requires enabling the `search` feature and start
connection in Search mode.
```rust,no_run
# use sonic_channel::*;
# fn main() -> result::Result<()> {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Search,
"localhost:1491",
"SecretPassword",
)?;
let result = ingest_channel.suggest("search", "default", "Beef")?;
dbg!(result);
# Ok(())
# }
```
"#]
use SuggestCommand for fn suggest<'a>(
collection: &'a str,
bucket: &'a str,
word: &'a str,
);
#[doc="Suggest auto-completes words with limit."]
#[doc=r#"
Suggest auto-completes words with limit.
Note: This method requires enabling the `search` feature and start
connection in Search mode.
```rust,no_run
# use sonic_channel::*;
# fn main() -> result::Result<()> {
let ingest_channel = SonicChannel::connect_with_start(
ChannelMode::Search,
"localhost:1491",
"SecretPassword",
)?;
let result = ingest_channel.suggest("search", "default", "Beef", 5)?;
dbg!(result);
# Ok(())
# }
```
"#]
use SuggestCommand for fn suggest_with_limit<'a>(
collection: &'a str,
bucket: &'a str,