doc: add examples for all sonic method
This commit is contained in:
parent
4875bffb4c
commit
85ddd8fb4e
1 changed files with 152 additions and 39 deletions
191
src/channel.rs
191
src/channel.rs
|
@ -223,9 +223,9 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let channel = SonicChannel::connect_with_start(
|
let channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Search,
|
ChannelMode::Search,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
channel.quit()?;
|
channel.quit()?;
|
||||||
|
@ -241,9 +241,9 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let channel = SonicChannel::connect_with_start(
|
let channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Search,
|
ChannelMode::Search,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
channel.ping()?;
|
channel.ping()?;
|
||||||
|
@ -265,16 +265,16 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let ingest_channel = SonicChannel::connect_with_start(
|
let ingest_channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Ingest,
|
ChannelMode::Ingest,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let result = ingest_channel.push(
|
let result = ingest_channel.push(
|
||||||
"search",
|
"search",
|
||||||
"default",
|
"default",
|
||||||
"recipe:295",
|
"recipe:295",
|
||||||
"Sweet Teriyaki Beef Skewers"
|
"Sweet Teriyaki Beef Skewers",
|
||||||
)?;
|
)?;
|
||||||
assert_eq!(result, true);
|
assert_eq!(result, true);
|
||||||
# Ok(())
|
# Ok(())
|
||||||
|
@ -298,24 +298,23 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let ingest_channel = SonicChannel::connect_with_start(
|
let ingest_channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Ingest,
|
ChannelMode::Ingest,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let result = ingest_channel.push_with_locale(
|
let result = ingest_channel.push_with_locale(
|
||||||
"search",
|
"search",
|
||||||
"default",
|
"default",
|
||||||
"recipe:296",
|
"recipe:296",
|
||||||
"Гренки с жареным картофелем и сыром",
|
"Гренки с жареным картофелем и сыром",
|
||||||
"rus"
|
"rus",
|
||||||
)?;
|
)?;
|
||||||
assert_eq!(result, true);
|
assert_eq!(result, true);
|
||||||
# Ok(())
|
# Ok(())
|
||||||
# }
|
# }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
#[doc=""]
|
|
||||||
use PushCommand for fn push_with_locale<'a>(
|
use PushCommand for fn push_with_locale<'a>(
|
||||||
collection: &'a str,
|
collection: &'a str,
|
||||||
bucket: &'a str,
|
bucket: &'a str,
|
||||||
|
@ -334,9 +333,9 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let ingest_channel = SonicChannel::connect_with_start(
|
let ingest_channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Ingest,
|
ChannelMode::Ingest,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let result = ingest_channel.pop("search", "default", "recipe:295", "beef")?;
|
let result = ingest_channel.pop("search", "default", "recipe:295", "beef")?;
|
||||||
|
@ -362,9 +361,9 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let ingest_channel = SonicChannel::connect_with_start(
|
let ingest_channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Ingest,
|
ChannelMode::Ingest,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let flushc_count = ingest_channel.flushc("search")?;
|
let flushc_count = ingest_channel.flushc("search")?;
|
||||||
|
@ -387,9 +386,9 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let ingest_channel = SonicChannel::connect_with_start(
|
let ingest_channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Ingest,
|
ChannelMode::Ingest,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let flushb_count = ingest_channel.flushb("search", "default")?;
|
let flushb_count = ingest_channel.flushb("search", "default")?;
|
||||||
|
@ -413,9 +412,9 @@ impl SonicChannel {
|
||||||
# use sonic_channel::*;
|
# use sonic_channel::*;
|
||||||
# fn main() -> result::Result<()> {
|
# fn main() -> result::Result<()> {
|
||||||
let ingest_channel = SonicChannel::connect_with_start(
|
let ingest_channel = SonicChannel::connect_with_start(
|
||||||
ChannelMode::Ingest,
|
ChannelMode::Ingest,
|
||||||
"localhost:1491",
|
"localhost:1491",
|
||||||
"SecretPassword"
|
"SecretPassword",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let flusho_count = ingest_channel.flusho("search", "default", "recipe:296")?;
|
let flusho_count = ingest_channel.flusho("search", "default", "recipe:296")?;
|
||||||
|
@ -433,14 +432,60 @@ impl SonicChannel {
|
||||||
|
|
||||||
#[cfg(feature = "search")]
|
#[cfg(feature = "search")]
|
||||||
init_commands! {
|
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>(
|
use QueryCommand for fn query<'a>(
|
||||||
collection: &'a str,
|
collection: &'a str,
|
||||||
bucket: &'a str,
|
bucket: &'a str,
|
||||||
terms: &'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>(
|
use QueryCommand for fn query_with_limit<'a>(
|
||||||
collection: &'a str,
|
collection: &'a str,
|
||||||
bucket: &'a str,
|
bucket: &'a str,
|
||||||
|
@ -448,7 +493,34 @@ impl SonicChannel {
|
||||||
limit: usize => Some(limit),
|
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>(
|
use QueryCommand for fn query_with_limit_and_offset<'a>(
|
||||||
collection: &'a str,
|
collection: &'a str,
|
||||||
bucket: &'a str,
|
bucket: &'a str,
|
||||||
|
@ -457,14 +529,55 @@ impl SonicChannel {
|
||||||
offset: usize => Some(offset),
|
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>(
|
use SuggestCommand for fn suggest<'a>(
|
||||||
collection: &'a str,
|
collection: &'a str,
|
||||||
bucket: &'a str,
|
bucket: &'a str,
|
||||||
word: &'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>(
|
use SuggestCommand for fn suggest_with_limit<'a>(
|
||||||
collection: &'a str,
|
collection: &'a str,
|
||||||
bucket: &'a str,
|
bucket: &'a str,
|
||||||
|
|
Loading…
Reference in a new issue