Fixed Server folder name

This commit is contained in:
2025-06-05 05:52:36 +00:00
parent b93b14f051
commit 183a150234
10 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
using Microsoft.AspNetCore.Mvc;
using embeddingsearch;
using System.Text.Json;
using Models;
using System.Text.Json.Nodes;
namespace server.Controllers;
[ApiController]
[Route("[controller]")]
public class EntityController : ControllerBase
{
private readonly ILogger<EntityController> _logger;
private readonly IConfiguration _config;
private SearchdomainManager _domainManager;
public EntityController(ILogger<EntityController> logger, IConfiguration config, SearchdomainManager domainManager)
{
_logger = logger;
_config = config;
_domainManager = domainManager;
}
[HttpGet("Query")]
public ActionResult<EntityQueryResults> Query(string searchdomain, string query)
{
Searchdomain searchdomain_;
try
{
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
} catch (Exception)
{
return Ok(new EntityQueryResults() {Results = []});
}
var results = searchdomain_.Search(query);
List<EntityQueryResult> queryResults = [.. results.Select(r => new EntityQueryResult
{
Name = r.Item2,
Value = r.Item1
})];
return Ok(new EntityQueryResults(){Results = queryResults});
}
[HttpPost("Index")]
public ActionResult<EntityIndexResult> Index(string searchdomain, [FromBody] List<JSONEntity>? jsonEntity)
{
Searchdomain searchdomain_;
try
{
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
}
catch (Exception)
{
return Ok(new EntityIndexResult() { Success = false });
}
List<Entity>? entities = searchdomain_.EntitiesFromJSON(JsonSerializer.Serialize(jsonEntity));
if (entities is not null)
{
_domainManager.InvalidateSearchdomainCache(searchdomain);
return Ok(new EntityIndexResult() { Success = true });
}
else
{
_logger.LogDebug("Unable to deserialize an entity");
}
return Ok(new EntityIndexResult() { Success = false });
}
[HttpGet("List")]
public ActionResult<EntityListResults> List(string searchdomain, bool returnEmbeddings = false)
{
Searchdomain searchdomain_;
try
{
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
} catch (Exception)
{
return Ok(new EntityListResults() {Results = [], Success = false});
}
EntityListResults entityListResults = new() {Results = [], Success = true};
foreach (Entity entity in searchdomain_.entityCache)
{
List<AttributeResult> attributeResults = [];
foreach (KeyValuePair<string, string> attribute in entity.attributes)
{
attributeResults.Add(new AttributeResult() {Name = attribute.Key, Value = attribute.Value});
}
List<DatapointResult> datapointResults = [];
foreach (Datapoint datapoint in entity.datapoints)
{
if (returnEmbeddings)
{
List<EmbeddingResult> embeddingResults = [];
foreach ((string, float[]) embedding in datapoint.embeddings)
{
embeddingResults.Add(new EmbeddingResult() {Model = embedding.Item1, Embeddings = embedding.Item2});
}
datapointResults.Add(new DatapointResult() {Name = datapoint.name, ProbMethod = datapoint.probMethod.Method.Name, Embeddings = embeddingResults});
}
else
{
datapointResults.Add(new DatapointResult() {Name = datapoint.name, ProbMethod = datapoint.probMethod.Method.Name, Embeddings = null});
}
}
EntityListResult entityListResult = new()
{
Name = entity.name,
Attributes = attributeResults,
Datapoints = datapointResults
};
entityListResults.Results.Add(entityListResult);
}
return Ok(entityListResults);
}
[HttpGet("Delete")]
public ActionResult<EntityDeleteResults> Delete(string searchdomain, string entityName) // TODO test this
{
Searchdomain searchdomain_;
try
{
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
} catch (Exception)
{
return Ok(new EntityDeleteResults() {Success = false});
}
Entity? entity_ = searchdomain_.GetEntity(entityName);
if (entity_ is null)
{
return Ok(new EntityDeleteResults() {Success = false});
}
searchdomain_.RemoveEntity(entityName);
return Ok(new EntityDeleteResults() {Success = true});
}
}

View File

@@ -0,0 +1,81 @@
using Microsoft.AspNetCore.Mvc;
using embeddingsearch;
using Models;
namespace server.Controllers;
[ApiController]
[Route("[controller]")]
public class SearchdomainController : ControllerBase
{
private readonly ILogger<SearchdomainController> _logger;
private readonly IConfiguration _config;
private SearchdomainManager _domainManager;
public SearchdomainController(ILogger<SearchdomainController> logger, IConfiguration config, SearchdomainManager domainManager)
{
_logger = logger;
_config = config;
_domainManager = domainManager;
}
[HttpGet("List")]
public ActionResult<SearchdomainListResults> List()
{
var results = _domainManager.ListSearchdomains()
?? throw new Exception("Unable to list searchdomains");
SearchdomainListResults searchdomainListResults = new() {Searchdomains = results};
return Ok(searchdomainListResults);
}
[HttpGet("Create")]
public ActionResult<SearchdomainCreateResults> Create(string searchdomain, string settings = "{}")
{
try
{
int id = _domainManager.CreateSearchdomain(searchdomain, settings);
return Ok(new SearchdomainCreateResults(){Id = id, Success = true});
} catch (Exception)
{
return Ok(new SearchdomainCreateResults(){Id = null, Success = false});
}
}
[HttpGet("Delete")]
public ActionResult<SearchdomainDeleteResults> Delete(string searchdomain)
{
bool success;
int deletedEntries;
try
{
success = true;
deletedEntries = _domainManager.DeleteSearchdomain(searchdomain);
} catch (Exception ex)
{
Console.WriteLine(ex);
success = false;
deletedEntries = 0;
}
return Ok(new SearchdomainDeleteResults(){Success = success, DeletedEntities = deletedEntries});
}
[HttpGet("Update")]
public ActionResult<SearchdomainUpdateResults> Update(string searchdomain, string newName, string settings = "{}")
{
try
{
Searchdomain searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
Dictionary<string, dynamic> parameters = new()
{
{"name", newName},
{"settings", settings},
{"id", searchdomain_.id}
};
searchdomain_.ExecuteSQLNonQuery("UPDATE searchdomain set name = @name, settings = @settings WHERE id = @id", parameters);
} catch (Exception)
{
return Ok(new SearchdomainUpdateResults(){Success = false});
}
return Ok(new SearchdomainUpdateResults(){Success = true});
}
}