Merge pull request #48 from LD-Reborn/40-add-attributes-to-query-result

40 add attributes to query result
This commit is contained in:
LD50
2025-12-25 12:39:18 +01:00
committed by GitHub
4 changed files with 8 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ using Server.Models;
namespace Server.Controllers; namespace Server.Controllers;
[ApiExplorerSettings(IgnoreApi = true)]
[Route("[Controller]")] [Route("[Controller]")]
public class AccountController : Controller public class AccountController : Controller
{ {

View File

@@ -25,7 +25,7 @@ public class EntityController : ControllerBase
} }
[HttpGet("Query")] [HttpGet("Query")]
public ActionResult<EntityQueryResults> Query(string searchdomain, string query, int? topN) public ActionResult<EntityQueryResults> Query(string searchdomain, string query, int? topN, bool returnAttributes = false)
{ {
Searchdomain searchdomain_; Searchdomain searchdomain_;
try try
@@ -44,7 +44,8 @@ public class EntityController : ControllerBase
List<EntityQueryResult> queryResults = [.. results.Select(r => new EntityQueryResult List<EntityQueryResult> queryResults = [.. results.Select(r => new EntityQueryResult
{ {
Name = r.Item2, Name = r.Item2,
Value = r.Item1 Value = r.Item1,
Attributes = returnAttributes ? (searchdomain_.entityCache.FirstOrDefault(x => x.name == r.Item2)?.attributes ?? null) : null
})]; })];
return Ok(new EntityQueryResults(){Results = queryResults, Success = true }); return Ok(new EntityQueryResults(){Results = queryResults, Success = true });
} }

View File

@@ -7,7 +7,7 @@ using Server.Exceptions;
using Server.Models; using Server.Models;
namespace Server.Controllers; namespace Server.Controllers;
[ApiController] [ApiExplorerSettings(IgnoreApi = true)]
[Route("/")] [Route("/")]
public class HomeController : Controller public class HomeController : Controller
{ {

View File

@@ -19,6 +19,9 @@ public class EntityQueryResult
public required string Name { get; set; } public required string Name { get; set; }
[JsonPropertyName("Value")] [JsonPropertyName("Value")]
public float Value { get; set; } public float Value { get; set; }
[JsonPropertyName("Attributes")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, string>? Attributes { get; set; }
} }
public class EntityIndexResult public class EntityIndexResult