|
@@ -5,6 +5,7 @@ use sonic_channel_wasi::{Dest, IngestChannel, PushRequest, QueryRequest, SearchC
|
|
#[cfg(not(target_os = "wasi"))]
|
|
#[cfg(not(target_os = "wasi"))]
|
|
use sonic_channel::{Dest, IngestChannel, PushRequest, QueryRequest, SearchChannel, SonicChannel};
|
|
use sonic_channel::{Dest, IngestChannel, PushRequest, QueryRequest, SearchChannel, SonicChannel};
|
|
use crate::config::Config;
|
|
use crate::config::Config;
|
|
|
|
+use crate::indexes::{Indexes, SerializableMessage};
|
|
|
|
|
|
pub struct IngestSonic{
|
|
pub struct IngestSonic{
|
|
ingest_channel: IngestChannel
|
|
ingest_channel: IngestChannel
|
|
@@ -27,7 +28,6 @@ impl IngestSonic{
|
|
}
|
|
}
|
|
|
|
|
|
pub fn ingest_document(&self, collection: &str, bucket: &str, object: &str, text: &str) -> anyhow::Result<()> {
|
|
pub fn ingest_document(&self, collection: &str, bucket: &str, object: &str, text: &str) -> anyhow::Result<()> {
|
|
- // TODO may be we need to store ingested email names and make a queue
|
|
|
|
let contents = Self::slice_string_into_chunks(&*text);
|
|
let contents = Self::slice_string_into_chunks(&*text);
|
|
for c in contents {
|
|
for c in contents {
|
|
let dest = Dest::col_buc(collection, bucket).obj(object);
|
|
let dest = Dest::col_buc(collection, bucket).obj(object);
|
|
@@ -67,16 +67,26 @@ impl IngestSonic{
|
|
pub struct SearchSonic{}
|
|
pub struct SearchSonic{}
|
|
|
|
|
|
impl SearchSonic{
|
|
impl SearchSonic{
|
|
- pub fn search_document(collection: &str, bucket: &str, query: &str, limit: i32, offset: i32) -> anyhow::Result<Vec<String>> {
|
|
|
|
|
|
+ pub fn search_document(collection: &str, bucket: &str, query: &str, limit: i32, offset: i32) -> anyhow::Result<Vec<SerializableMessage>> {
|
|
let search = SearchChannel::start(
|
|
let search = SearchChannel::start(
|
|
format!("{}:{}", Config::global().sonic_search_addr, Config::global().sonic_search_port),
|
|
format!("{}:{}", Config::global().sonic_search_addr, Config::global().sonic_search_port),
|
|
Config::global().sonic_search_password.clone()
|
|
Config::global().sonic_search_password.clone()
|
|
)?;
|
|
)?;
|
|
- let results: Vec<String> = search.query(QueryRequest::new(
|
|
|
|
|
|
+ let ids: Vec<String> = search.query(QueryRequest::new(
|
|
Dest::col_buc(collection, bucket),
|
|
Dest::col_buc(collection, bucket),
|
|
query
|
|
query
|
|
).limit(limit as usize).offset(offset as usize)).unwrap_or_else(|_| { vec![] });
|
|
).limit(limit as usize).offset(offset as usize)).unwrap_or_else(|_| { vec![] });
|
|
search.quit()?;
|
|
search.quit()?;
|
|
|
|
+
|
|
|
|
+ let mut results: Vec<SerializableMessage> = vec![];
|
|
|
|
+ let messages = Indexes::get_messages()?;
|
|
|
|
+ for id in ids {
|
|
|
|
+ match Indexes::find_by_id(&messages, id) {
|
|
|
|
+ None => {}
|
|
|
|
+ Some(message) => results.push(message)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
Ok(results)
|
|
Ok(results)
|
|
}
|
|
}
|
|
}
|
|
}
|