feat: add pop command to ingest mode
This commit is contained in:
parent
31053815d7
commit
04f52bb076
3 changed files with 55 additions and 0 deletions
|
@ -220,6 +220,21 @@ impl SonicChannel {
|
|||
locale: &'a str => Some(locale),
|
||||
);
|
||||
|
||||
#[doc=r#"
|
||||
Pop search data from the index. Returns removed words count as u32 type.
|
||||
|
||||
```rust
|
||||
let result = ingest_channel.pop("search", "default", "recipe:295", "cake")?;
|
||||
dbg!(result);
|
||||
```
|
||||
"#]
|
||||
use PopCommand for fn pop<'a>(
|
||||
collection: &'a str,
|
||||
bucket: &'a str,
|
||||
object: &'a str,
|
||||
text: &'a str,
|
||||
);
|
||||
|
||||
#[doc="Flush all indexed data from collections."]
|
||||
use FlushCommand for fn flushc<'a>(
|
||||
collection: &'a str,
|
||||
|
|
|
@ -6,6 +6,8 @@ mod ping;
|
|||
#[cfg(feature = "ingest")]
|
||||
mod flush;
|
||||
#[cfg(feature = "ingest")]
|
||||
mod pop;
|
||||
#[cfg(feature = "ingest")]
|
||||
mod push;
|
||||
|
||||
#[cfg(feature = "search")]
|
||||
|
@ -22,6 +24,8 @@ pub use ping::PingCommand;
|
|||
pub use flush::FlushCommand;
|
||||
#[cfg(feature = "ingest")]
|
||||
pub use push::PushCommand;
|
||||
#[cfg(feature = "ingest")]
|
||||
pub use pop::PopCommand;
|
||||
|
||||
#[cfg(feature = "search")]
|
||||
pub use query::QueryCommand;
|
||||
|
|
36
src/commands/pop.rs
Normal file
36
src/commands/pop.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use super::StreamCommand;
|
||||
use crate::result::{Error, ErrorKind, Result};
|
||||
|
||||
#[doc(hidden)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PopCommand<'a> {
|
||||
pub collection: &'a str,
|
||||
pub bucket: &'a str,
|
||||
pub object: &'a str,
|
||||
pub text: &'a str,
|
||||
}
|
||||
|
||||
impl StreamCommand for PopCommand<'_> {
|
||||
type Response = u32;
|
||||
|
||||
fn message(&self) -> String {
|
||||
let mut message = format!(
|
||||
r#"POP {} {} {} "{}""#,
|
||||
self.collection, self.bucket, self.object, self.text
|
||||
);
|
||||
message.push_str("\r\n");
|
||||
message
|
||||
}
|
||||
|
||||
fn receive(&self, message: String) -> Result<Self::Response> {
|
||||
if message.starts_with("RESULT") {
|
||||
let count = message.split_whitespace().last().unwrap_or_default();
|
||||
count
|
||||
.parse()
|
||||
.map_err(|_| Error::new(ErrorKind::QueryResponseError("Cannot parse pop count")))
|
||||
|
||||
} else {
|
||||
Err(Error::new(ErrorKind::QueryResponseError("Cannot parse result")))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue