mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: integrate cloud document search (#5523)
This commit is contained in:
@ -40,6 +40,7 @@ flowy-document-pub = { workspace = true }
|
||||
appflowy-cloud-billing-client = { workspace = true }
|
||||
flowy-error = { workspace = true, features = ["impl_from_serde", "impl_from_reqwest", "impl_from_url", "impl_from_appflowy_cloud"] }
|
||||
flowy-server-pub = { workspace = true }
|
||||
flowy-search-pub = { workspace = true }
|
||||
flowy-encrypt = { workspace = true }
|
||||
flowy-storage = { workspace = true }
|
||||
flowy-chat-pub = { workspace = true }
|
||||
|
@ -3,6 +3,7 @@ pub(crate) use database::*;
|
||||
pub(crate) use document::*;
|
||||
pub(crate) use file_storage::*;
|
||||
pub(crate) use folder::*;
|
||||
pub(crate) use search::*;
|
||||
pub(crate) use user::*;
|
||||
|
||||
mod chat;
|
||||
@ -10,5 +11,6 @@ mod database;
|
||||
mod document;
|
||||
mod file_storage;
|
||||
mod folder;
|
||||
mod search;
|
||||
mod user;
|
||||
mod util;
|
||||
|
40
frontend/rust-lib/flowy-server/src/af_cloud/impls/search.rs
Normal file
40
frontend/rust-lib/flowy-server/src/af_cloud/impls/search.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use client_api::entity::search_dto::SearchDocumentResponseItem;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_search_pub::cloud::SearchCloudService;
|
||||
use lib_infra::async_trait::async_trait;
|
||||
|
||||
use crate::af_cloud::AFServer;
|
||||
|
||||
pub(crate) struct AFCloudSearchCloudServiceImpl<T> {
|
||||
pub inner: T,
|
||||
}
|
||||
|
||||
// The limit of what the score should be for results, used to
|
||||
// filter out irrelevant results.
|
||||
const SCORE_LIMIT: f64 = 0.8;
|
||||
const DEFAULT_PREVIEW: u32 = 80;
|
||||
|
||||
#[async_trait]
|
||||
impl<T> SearchCloudService for AFCloudSearchCloudServiceImpl<T>
|
||||
where
|
||||
T: AFServer,
|
||||
{
|
||||
async fn document_search(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
query: String,
|
||||
) -> Result<Vec<SearchDocumentResponseItem>, FlowyError> {
|
||||
let client = self.inner.try_get_client()?;
|
||||
let result = client
|
||||
.search_documents(workspace_id, &query, 10, DEFAULT_PREVIEW)
|
||||
.await?;
|
||||
|
||||
// Filter out irrelevant results
|
||||
let result = result
|
||||
.into_iter()
|
||||
.filter(|r| r.score < SCORE_LIMIT)
|
||||
.collect();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ use client_api::ws::{
|
||||
};
|
||||
use client_api::{Client, ClientConfiguration};
|
||||
use flowy_chat_pub::cloud::ChatCloudService;
|
||||
use flowy_search_pub::cloud::SearchCloudService;
|
||||
use flowy_storage::ObjectStorageService;
|
||||
use rand::Rng;
|
||||
use semver::Version;
|
||||
@ -38,6 +39,8 @@ use crate::af_cloud::impls::{
|
||||
|
||||
use crate::AppFlowyServer;
|
||||
|
||||
use super::impls::AFCloudSearchCloudServiceImpl;
|
||||
|
||||
pub(crate) type AFCloudClient = Client;
|
||||
|
||||
pub struct AppFlowyCloudServer {
|
||||
@ -255,6 +258,14 @@ impl AppFlowyServer for AppFlowyCloudServer {
|
||||
};
|
||||
Some(Arc::new(AFCloudFileStorageServiceImpl::new(client)))
|
||||
}
|
||||
|
||||
fn search_service(&self) -> Option<Arc<dyn SearchCloudService>> {
|
||||
let server = AFServerImpl {
|
||||
client: self.get_client(),
|
||||
};
|
||||
|
||||
Some(Arc::new(AFCloudSearchCloudServiceImpl { inner: server }))
|
||||
}
|
||||
}
|
||||
|
||||
/// Spawns a new asynchronous task to handle WebSocket connections based on token state.
|
||||
|
@ -1,3 +1,4 @@
|
||||
use flowy_search_pub::cloud::SearchCloudService;
|
||||
use flowy_storage::ObjectStorageService;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -70,4 +71,8 @@ impl AppFlowyServer for LocalServer {
|
||||
fn file_storage(&self) -> Option<Arc<dyn ObjectStorageService>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn search_service(&self) -> Option<Arc<dyn SearchCloudService>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use client_api::ws::ConnectState;
|
||||
use client_api::ws::WSConnectStateReceiver;
|
||||
use client_api::ws::WebSocketChannel;
|
||||
use flowy_search_pub::cloud::SearchCloudService;
|
||||
use flowy_storage::ObjectStorageService;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -100,6 +101,10 @@ pub trait AppFlowyServer: Send + Sync + 'static {
|
||||
Arc::new(DefaultChatCloudServiceImpl)
|
||||
}
|
||||
|
||||
/// Bridge for the Cloud AI Search features
|
||||
///
|
||||
fn search_service(&self) -> Option<Arc<dyn SearchCloudService>>;
|
||||
|
||||
/// Manages collaborative objects within a remote storage system. This includes operations such as
|
||||
/// checking storage status, retrieving updates and snapshots, and dispatching updates. The service
|
||||
/// also provides subscription capabilities for real-time updates.
|
||||
|
@ -1,3 +1,4 @@
|
||||
use flowy_search_pub::cloud::SearchCloudService;
|
||||
use flowy_storage::ObjectStorageService;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Weak};
|
||||
@ -194,4 +195,8 @@ impl AppFlowyServer for SupabaseServer {
|
||||
.clone()
|
||||
.map(|s| s as Arc<dyn ObjectStorageService>)
|
||||
}
|
||||
|
||||
fn search_service(&self) -> Option<Arc<dyn SearchCloudService>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user