chore: enable cloud search (#5624)

* chore: enable cloud search

* fix: filter received msgs by query
This commit is contained in:
Mathias Mogensen 2024-06-25 21:56:58 +02:00 committed by GitHub
parent a7f40b2adc
commit e4132ed217
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 47 additions and 31 deletions

View File

@ -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({

View File

@ -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;

View File

@ -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(

View File

@ -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,
),
);
}

View File

@ -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]))
}
}

View File

@ -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)]

View File

@ -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));