[mob] Show score if query contains score threshold

This commit is contained in:
Neeraj Gupta
2024-08-19 14:18:45 +05:30
parent 329f320720
commit aaebef5b22
3 changed files with 17 additions and 1 deletions

View File

@@ -268,9 +268,11 @@ class EnteFile {
}
String? get caption {
return pubMagicMetadata?.caption;
return debugCaption ?? pubMagicMetadata?.caption;
}
String? debugCaption;
String get thumbnailUrl {
if (localFileServer.isNotEmpty) {
return "$localFileServer/thumb/$uploadedFileID";

View File

@@ -144,12 +144,14 @@ class SemanticSearchService {
String query, {
double? scoreThreshold,
}) async {
bool showScore = false;
// if the query starts with 0.xxx, the split the query to get score threshold and actual query
if (query.startsWith(RegExp(r"0\.\d+"))) {
final parts = query.split(" ");
if (parts.length > 1) {
scoreThreshold = double.parse(parts[0]);
query = parts.sublist(1).join(" ");
showScore = true;
}
}
final textEmbedding = await _getTextEmbedding(query);
@@ -165,6 +167,11 @@ class SemanticSearchService {
dev.log("Query: $query, Score: ${result.score}, index $i");
}
final Map<int, double> fileIDToScoreMap = {};
for (final result in queryResults) {
fileIDToScoreMap[result.id] = result.score;
}
final filesMap = await FilesDB.instance
.getFilesFromIDs(queryResults.map((e) => e.id).toList());
@@ -177,8 +184,13 @@ class SemanticSearchService {
for (final result in queryResults) {
final file = filesMap[result.id];
if (file != null && !ignoredCollections.contains(file.collectionID)) {
if (showScore) {
file.debugCaption =
"${fileIDToScoreMap[result.id]?.toStringAsFixed(3)}";
}
results.add(file);
}
if (file == null) {
deletedEntries.add(result.id);
}

View File

@@ -201,6 +201,8 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
viewChildren.add(TrashedFileOverlayText(widget.file as TrashFile));
} else if (GalleryContextState.of(context)?.type == GroupType.size) {
viewChildren.add(FileSizeOverlayText(widget.file));
} else if (widget.file.debugCaption != null) {
viewChildren.add(FileOverlayText(widget.file.debugCaption!));
}
// todo: Move this icon overlay to the collection widget.
if (widget.shouldShowArchiveStatus) {