Added search cache updating

This commit is contained in:
2025-12-22 16:52:06 +01:00
parent ee12986fef
commit 8b36c65437
3 changed files with 49 additions and 3 deletions

View File

@@ -185,6 +185,36 @@ public class SearchdomainController : ControllerBase
return Ok(new SearchdomainDeleteSearchResult() {Success = false, Message = "Query not found in search cache"}); return Ok(new SearchdomainDeleteSearchResult() {Success = false, Message = "Query not found in search cache"});
} }
[HttpPatch("Searches")]
public ActionResult<SearchdomainUpdateSearchResult> UpdateSearch(string searchdomain, string query, [FromBody]List<ResultItem> results)
{
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 SearchdomainUpdateSearchResult() { 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 SearchdomainUpdateSearchResult() { Success = false, Message = ex.Message });
}
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
bool containsKey = searchCache.ContainsKey(query);
if (containsKey)
{
DateTimedSearchResult element = searchCache[query];
element.Results = results;
searchCache[query] = element;
return Ok(new SearchdomainUpdateSearchResult() {Success = true});
}
return Ok(new SearchdomainUpdateSearchResult() {Success = false, Message = "Query not found in search cache"});
}
[HttpGet("GetSettings")] [HttpGet("GetSettings")]
public ActionResult<SearchdomainSettingsResults> GetSettings(string searchdomain) public ActionResult<SearchdomainSettingsResults> GetSettings(string searchdomain)
{ {

View File

@@ -2,12 +2,19 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Shared.Models; namespace Shared.Models;
public readonly struct ResultItem(float score, string name) public readonly struct ResultItem
{ {
[JsonPropertyName("Score")] [JsonPropertyName("Score")]
public readonly float Score { get; } = score; public readonly float Score { get; }
[JsonPropertyName("Name")] [JsonPropertyName("Name")]
public readonly string Name { get; } = name; public readonly string Name { get; }
[JsonConstructor]
public ResultItem(float score, string name)
{
Score = score;
Name = name;
}
public static long EstimateSize(ResultItem item) public static long EstimateSize(ResultItem item)
{ {

View File

@@ -64,6 +64,15 @@ public class SearchdomainDeleteSearchResult
public string? Message { get; set; } public string? Message { get; set; }
} }
public class SearchdomainUpdateSearchResult
{
[JsonPropertyName("Success")]
public required bool Success { get; set; }
[JsonPropertyName("Message")]
public string? Message { get; set; }
}
public class SearchdomainSettingsResults public class SearchdomainSettingsResults
{ {
[JsonPropertyName("Success")] [JsonPropertyName("Success")]