Implemented search result endpoint

This commit is contained in:
2025-12-14 23:13:34 +01:00
parent 1f67682879
commit 21194f99d3
5 changed files with 58 additions and 28 deletions

View File

@@ -105,4 +105,27 @@ public class SearchdomainController : ControllerBase
}
return Ok(new SearchdomainUpdateResults(){Success = true});
}
[HttpGet("GetSearches")]
public ActionResult<SearchdomainSearchesResults> GetSearches(string searchdomain)
{
Searchdomain searchdomain_;
try
{
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
}
catch (SearchdomainNotFoundException)
{
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
return Ok(new SearchdomainSearchesResults() { Searches = [], Success = false, Message = "Searchdomain not found" });
}
catch (Exception ex)
{
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]);
return Ok(new SearchdomainSearchesResults() { Searches = [], Success = false, Message = ex.Message });
}
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true });
}
}

View File

@@ -1,19 +0,0 @@
using MySqlX.XDevAPI.Common;
namespace Server.Models;
public readonly struct ResultItem(float score, string name)
{
public readonly float Score = score;
public readonly string Name = name;
}
public struct DateTimedSearchResult
{
public List<DateTime> accessTimes;
public SearchResult Results;
}
public readonly struct SearchResult(List<ResultItem> results)
{
public readonly List<ResultItem> Results = results;
}

View File

@@ -3,7 +3,7 @@ using System.Data.Common;
using ElmahCore.Mvc.Logger;
using MySql.Data.MySqlClient;
using Server.Helper;
using Server.Models;
using Shared.Models;
namespace Server;
@@ -155,8 +155,8 @@ public class Searchdomain
{
if (searchCache.TryGetValue(query, out DateTimedSearchResult cachedResult))
{
cachedResult.accessTimes.Add(DateTime.Now);
return [.. cachedResult.Results.Results.Select(r => (r.Score, r.Name))];
cachedResult.AccessDateTimes.Add(DateTime.Now);
return [.. cachedResult.Results.Select(r => (r.Score, r.Name))];
}
if (!embeddingCache.TryGetValue(query, out Dictionary<string, float[]>? queryEmbeddings))
@@ -188,15 +188,11 @@ public class Searchdomain
result.Add((entity.probMethod(datapointProbs), entity.name));
}
List<(float, string)> results = [.. result.OrderByDescending(s => s.Item1)];
SearchResult searchResult = new(
List<ResultItem> searchResult = new(
[.. results.Select(r =>
new ResultItem(r.Item1, r.Item2 ))]
);
searchCache[query] = new DateTimedSearchResult
{
accessTimes = [DateTime.Now],
Results = searchResult
};
searchCache[query] = new DateTimedSearchResult(DateTime.Now, searchResult);
return results;
}