6ca415c134
Chat hits sort by the chat's last use whatever field matched, and run, step, field, artifact and pipeline hits sort by their own date, before the result cap applies so the cap drops the oldest. Each kind's row scan also walks newest first. Score still reports the match tier. The app sorts both groups newest first as well.
87 lines
2.5 KiB
Dart
87 lines
2.5 KiB
Dart
import '../../../core/api_gateway.dart';
|
|
import '../data/search_repository.dart';
|
|
import 'search_models.dart';
|
|
import 'search_order.dart';
|
|
import 'search_query.dart';
|
|
|
|
/// Wording for a server whose search does not know the `chat` kind (it
|
|
/// predates chat search and rejects the kind by name).
|
|
const unsupportedChatSearchCopy =
|
|
'This server does not search chats. Update the Pipelines server to '
|
|
'include them.';
|
|
|
|
final _unknownKind = RegExp(r'unknown search kind', caseSensitive: false);
|
|
|
|
/// The Chats section's state: one `kind: chat` request per sent query, run
|
|
/// beside (never instead of, nor ahead of) the run/artifact search, so the
|
|
/// server's transcript readback cannot delay the other results.
|
|
class SearchChatSlice {
|
|
List<JsonMap> results = const [];
|
|
bool loading = false;
|
|
bool loaded = false;
|
|
bool truncated = false;
|
|
String? error;
|
|
|
|
void clear() {
|
|
results = const [];
|
|
loading = false;
|
|
loaded = false;
|
|
truncated = false;
|
|
error = null;
|
|
}
|
|
|
|
/// Requests chats for [query]. [current] reports whether this request is
|
|
/// still the newest edit; a stale reply is dropped without a change.
|
|
Future<void> load(
|
|
SearchRepository repository,
|
|
String query, {
|
|
required bool Function() current,
|
|
required void Function() changed,
|
|
}) async {
|
|
loading = true;
|
|
error = null;
|
|
changed();
|
|
try {
|
|
final response = await repository.search(
|
|
query: query,
|
|
kind: SearchKind.chat,
|
|
);
|
|
if (!current()) return;
|
|
if (response == null) {
|
|
results = const [];
|
|
truncated = false;
|
|
error = unsupportedChatSearchCopy;
|
|
} else {
|
|
results = searchHitsNewestFirst(
|
|
response.results
|
|
.where((hit) => hit['kind'] == SearchKind.chat.wire)
|
|
.toList(growable: false),
|
|
);
|
|
truncated = response.truncated;
|
|
}
|
|
} catch (failure) {
|
|
if (!current()) return;
|
|
results = const [];
|
|
truncated = false;
|
|
final text = searchFailureText(failure);
|
|
error = _unknownKind.hasMatch(text) || text == unsupportedSearchCopy
|
|
? unsupportedChatSearchCopy
|
|
: text;
|
|
}
|
|
loading = false;
|
|
loaded = true;
|
|
changed();
|
|
}
|
|
|
|
/// A short honest note under the Chats section: why chats are missing, or
|
|
/// that the server's bounds left some transcripts unsearched.
|
|
String? get note {
|
|
if (error != null) return error;
|
|
if (truncated) {
|
|
return "Some chats were not searched within the server's time or "
|
|
'result limit.';
|
|
}
|
|
return null;
|
|
}
|
|
}
|