Skip to content

Commit

Permalink
chore: updated matches implementation for visual fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendomey committed Feb 25, 2025
1 parent 8c5edcb commit f229451
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion services/main/Controllers/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public async Task<IActionResult> VisualSearch(

var matches = await _searchContentService.AskRekognitionForMatch(media);

if (matches == null)
if (matches == null || matches.Length == 0)
{
var res = HttpLib.GeneratePagination<OutputContent, Models.Content>(
[],
Expand Down
22 changes: 7 additions & 15 deletions services/main/Domains/Content/SearchContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,16 @@ GetContentsInput input
FilterDefinitionBuilder<Content> builder = Builders<Content>.Filter;
var filter = builder.Empty;

var validIds = matches.Where(match => ObjectId.TryParse(match, out _)).ToList();

matches.ToList().ForEach(match =>
if (validIds.Count > 0)
{
if (!ObjectId.TryParse(match, out _))
{
return;
}
var idFilter = Builders<Content>.Filter.Or(
validIds.ConvertAll(id => Builders<Content>.Filter.Eq(r => r.Id, id))
);
filter = idFilter;
}

var idFilter = builder.Eq(r => r.Id, match);
filter |= idFilter;
});

if (filter == builder.Empty)
{
Expand Down Expand Up @@ -100,14 +99,7 @@ public async Task<List<Content>> VisualSearch(
GetContentsInput input
)
{
FilterDefinitionBuilder<Content> builder = Builders<Content>.Filter;

var filter = filterLogicForVisualSearch(matches, input);
if (filter == builder.Empty)
{
return [];
}


var contents = await _contentsCollection
.Find(filter)
Expand Down

0 comments on commit f229451

Please sign in to comment.