Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: enable cloud search (#5624)

Mathias Mogensene4132ed21782
diff --git a/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart
index 8064f7038c..7787525847 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart
@@ -7,6 +7,7 @@ import 'package:appflowy/plugins/trash/application/trash_service.dart';
import 'package:appflowy/workspace/application/command_palette/search_listener.dart';
import 'package:appflowy/workspace/application/command_palette/search_service.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/trash.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-search/notification.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -40,6 +41,7 @@ class CommandPaletteBloc
Future<void> close() {
_trashListener.close();
_searchListener.stop();
+ _debounceOnChanged?.cancel();
return super.close();
}
@@ -75,13 +77,17 @@ class CommandPaletteBloc
emit(state.copyWith(query: null, isLoading: false, results: []));
}
},
- resultsChanged: (results, max) {
+ resultsChanged: (results) {
if (state.query != _oldQuery) {
- emit(state.copyWith(results: []));
+ emit(state.copyWith(results: [], isLoading: true));
_oldQuery = state.query;
_messagesReceived = 0;
}
+ if (state.query != results.query) {
+ return;
+ }
+
_messagesReceived++;
final searchResults = _filterDuplicates(results.items);
@@ -90,7 +96,7 @@ class CommandPaletteBloc
emit(
state.copyWith(
results: searchResults,
- isLoading: _messagesReceived != max,
+ isLoading: _messagesReceived != results.sends.toInt(),
),
);
},
@@ -155,7 +161,7 @@ class CommandPaletteBloc
void _performSearch(String value) =>
add(CommandPaletteEvent.performSearch(search: value));
- void _onResultsChanged(RepeatedSearchResultPB results) =>
+ void _onResultsChanged(SearchResultNotificationPB results) =>
add(CommandPaletteEvent.resultsChanged(results: results));
}
@@ -168,8 +174,7 @@ class CommandPaletteEvent with _$CommandPaletteEvent {
_PerformSearch;
const factory CommandPaletteEvent.resultsChanged({
- required RepeatedSearchResultPB results,
- @Default(1) int max,
+ required SearchResultNotificationPB results,
}) = _ResultsChanged;
const factory CommandPaletteEvent.trashChanged({
diff --git a/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_listener.dart b/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_listener.dart
index ef7e59e695..b22630eb74 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_listener.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_listener.dart
@@ -4,8 +4,7 @@ import 'dart:typed_data';
import 'package:appflowy/core/notification/search_notification.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-search/notification.pbenum.dart';
-import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-search/notification.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:flowy_infra/notifier.dart';
@@ -23,14 +22,15 @@ class SearchListener {
///
final String? channel;
- PublishNotifier<RepeatedSearchResultPB>? _updateNotifier = PublishNotifier();
- PublishNotifier<RepeatedSearchResultPB>? _updateDidCloseNotifier =
+ PublishNotifier<SearchResultNotificationPB>? _updateNotifier =
+ PublishNotifier();
+ PublishNotifier<SearchResultNotificationPB>? _updateDidCloseNotifier =
PublishNotifier();
SearchNotificationListener? _listener;
void start({
- void Function(RepeatedSearchResultPB)? onResultsChanged,
- void Function(RepeatedSearchResultPB)? onResultsClosed,
+ void Function(SearchResultNotificationPB)? onResultsChanged,
+ void Function(SearchResultNotificationPB)? onResultsClosed,
}) {
if (onResultsChanged != null) {
_updateNotifier?.addPublishListener(onResultsChanged);
@@ -55,7 +55,7 @@ class SearchListener {
case SearchNotification.DidUpdateResults:
result.fold(
(payload) => _updateNotifier?.value =
- RepeatedSearchResultPB.fromBuffer(payload),
+ SearchResultNotificationPB.fromBuffer(payload),
(err) => Log.error(err),
);
break;
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart
index ae61f9d7a2..e102ef8f25 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart
@@ -141,7 +141,8 @@ class CommandPaletteModal extends StatelessWidget {
),
),
],
- if (state.results.isNotEmpty) ...[
+ if (state.results.isNotEmpty &&
+ (state.query?.isNotEmpty ?? false)) ...[
const Divider(height: 0),
Flexible(
child: SearchResultsList(
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_tile.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_tile.dart
index 770f37beee..0edcde3664 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_tile.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_tile.dart
@@ -93,20 +93,25 @@ class _SearchResultTileState extends State<SearchResultTile> {
SizedBox(width: 24, child: icon),
const HSpace(6),
],
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- if (widget.isTrashed) ...[
+ Flexible(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ if (widget.isTrashed) ...[
+ FlowyText(
+ LocaleKeys.commandPalette_fromTrashHint.tr(),
+ color: AFThemeExtension.of(context)
+ .textColor
+ .withAlpha(175),
+ fontSize: 10,
+ ),
+ ],
FlowyText(
- LocaleKeys.commandPalette_fromTrashHint.tr(),
- color: AFThemeExtension.of(context)
- .textColor
- .withAlpha(175),
- fontSize: 10,
+ widget.result.data,
+ overflow: TextOverflow.ellipsis,
),
],
- FlowyText(widget.result.data),
- ],
+ ),
),
],
),
@@ -142,6 +147,7 @@ class _DocumentPreview extends StatelessWidget {
color: Theme.of(context).hintColor,
fontSize: 12,
maxLines: 3,
+ overflow: TextOverflow.ellipsis,
),
);
}
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/search_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/search_deps.rs
index cbb6e3c7d7..b31853a803 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/search_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/search_deps.rs
@@ -1,4 +1,5 @@
use flowy_folder::manager::FolderManager;
+use flowy_search::document::handler::DocumentSearchHandler;
use flowy_search::folder::handler::FolderSearchHandler;
use flowy_search::folder::indexer::FolderIndexManagerImpl;
use flowy_search::services::manager::SearchManager;
@@ -9,12 +10,11 @@ pub struct SearchDepsResolver();
impl SearchDepsResolver {
pub async fn resolve(
folder_indexer: Arc<FolderIndexManagerImpl>,
- _cloud_service: Arc<dyn SearchCloudService>,
- _folder_manager: Arc<FolderManager>,
+ cloud_service: Arc<dyn SearchCloudService>,
+ folder_manager: Arc<FolderManager>,
) -> Arc<SearchManager> {
let folder_handler = Arc::new(FolderSearchHandler::new(folder_indexer));
- // TODO(Mathias): Enable when Cloud Search is ready
- // let document_handler = Arc::new(DocumentSearchHandler::new(cloud_service, folder_manager));
- Arc::new(SearchManager::new(vec![folder_handler]))
+ let document_handler = Arc::new(DocumentSearchHandler::new(cloud_service, folder_manager));
+ Arc::new(SearchManager::new(vec![folder_handler, document_handler]))
}
}
diff --git a/frontend/rust-lib/flowy-search/src/entities/notification.rs b/frontend/rust-lib/flowy-search/src/entities/notification.rs
index e05f46dd09..a28ed2b5d8 100644
--- a/frontend/rust-lib/flowy-search/src/entities/notification.rs
+++ b/frontend/rust-lib/flowy-search/src/entities/notification.rs
@@ -12,6 +12,9 @@ pub struct SearchResultNotificationPB {
#[pb(index = 3, one_of)]
pub channel: Option<String>,
+
+ #[pb(index = 4)]
+ pub query: String,
}
#[derive(ProtoBuf_Enum, Debug, Default)]
diff --git a/frontend/rust-lib/flowy-search/src/services/manager.rs b/frontend/rust-lib/flowy-search/src/services/manager.rs
index aec33a5b60..35e7e2c1cb 100644
--- a/frontend/rust-lib/flowy-search/src/services/manager.rs
+++ b/frontend/rust-lib/flowy-search/src/services/manager.rs
@@ -72,7 +72,7 @@ impl SearchManager {
let notifier = self.notifier.clone();
af_spawn(async move {
- let res = handler.perform_search(q, f).await;
+ let res = handler.perform_search(q.clone(), f).await;
let items = res.unwrap_or_default();
@@ -80,6 +80,7 @@ impl SearchManager {
items,
sends: max as u64,
channel: ch,
+ query: q,
};
let _ = notifier.send(SearchResultChanged::SearchResultUpdate(notification));