Merge pull request #53 from LD-Reborn/33-move-query-from-entity-to-searchdomain
33 move query from entity to searchdomain
This commit is contained in:
@@ -89,7 +89,7 @@ public class Client
|
|||||||
|
|
||||||
public async Task<EntityQueryResults> EntityQueryAsync(string searchdomain, string query)
|
public async Task<EntityQueryResults> EntityQueryAsync(string searchdomain, string query)
|
||||||
{
|
{
|
||||||
return await GetUrlAndProcessJson<EntityQueryResults>(GetUrl($"{baseUri}/Entity", "Query", apiKey, new Dictionary<string, string>()
|
return await GetUrlAndProcessJson<EntityQueryResults>(GetUrl($"{baseUri}/Searchdomain", "Query", apiKey, new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{"searchdomain", searchdomain},
|
{"searchdomain", searchdomain},
|
||||||
{"query", query}
|
{"query", query}
|
||||||
|
|||||||
@@ -24,32 +24,6 @@ public class EntityController : ControllerBase
|
|||||||
_databaseHelper = databaseHelper;
|
_databaseHelper = databaseHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("Query")]
|
|
||||||
public ActionResult<EntityQueryResults> Query(string searchdomain, string query, int? topN, bool returnAttributes = false)
|
|
||||||
{
|
|
||||||
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 EntityQueryResults() {Results = [], 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 EntityQueryResults() {Results = [], Success = false, Message = "Unable to retrieve the searchdomain - it likely exists, but some other error happened." });
|
|
||||||
}
|
|
||||||
List<(float, string)> results = searchdomain_.Search(query, topN);
|
|
||||||
List<EntityQueryResult> queryResults = [.. results.Select(r => new EntityQueryResult
|
|
||||||
{
|
|
||||||
Name = r.Item2,
|
|
||||||
Value = r.Item1,
|
|
||||||
Attributes = returnAttributes ? (searchdomain_.entityCache.FirstOrDefault(x => x.name == r.Item2)?.attributes ?? null) : null
|
|
||||||
})];
|
|
||||||
return Ok(new EntityQueryResults(){Results = queryResults, Success = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("Index")]
|
[HttpPost("Index")]
|
||||||
public ActionResult<EntityIndexResult> Index([FromBody] List<JSONEntity>? jsonEntities)
|
public ActionResult<EntityIndexResult> Index([FromBody] List<JSONEntity>? jsonEntities)
|
||||||
{
|
{
|
||||||
@@ -95,21 +69,10 @@ public class EntityController : ControllerBase
|
|||||||
if (returnEmbeddings && !returnModels)
|
if (returnEmbeddings && !returnModels)
|
||||||
{
|
{
|
||||||
_logger.LogError("Invalid request for {searchdomain} - embeddings return requested but without models - not possible!", [searchdomain]);
|
_logger.LogError("Invalid request for {searchdomain} - embeddings return requested but without models - not possible!", [searchdomain]);
|
||||||
return Ok(new EntityQueryResults() {Results = [], Success = false, Message = "Invalid request" });
|
return BadRequest(new EntityListResults() {Results = [], Success = false, Message = "Invalid request" });
|
||||||
}
|
|
||||||
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 EntityQueryResults() {Results = [], 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 EntityQueryResults() {Results = [], Success = false, Message = "Unable to retrieve the searchdomain - it likely exists, but some other error happened." });
|
|
||||||
}
|
}
|
||||||
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
EntityListResults entityListResults = new() {Results = [], Success = true};
|
EntityListResults entityListResults = new() {Results = [], Success = true};
|
||||||
foreach (Entity entity in searchdomain_.entityCache)
|
foreach (Entity entity in searchdomain_.entityCache)
|
||||||
{
|
{
|
||||||
@@ -150,19 +113,8 @@ public class EntityController : ControllerBase
|
|||||||
[HttpGet("Delete")]
|
[HttpGet("Delete")]
|
||||||
public ActionResult<EntityDeleteResults> Delete(string searchdomain, string entityName)
|
public ActionResult<EntityDeleteResults> Delete(string searchdomain, string entityName)
|
||||||
{
|
{
|
||||||
Searchdomain searchdomain_;
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
try
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
{
|
|
||||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
} catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
|
||||||
return Ok(new EntityQueryResults() {Results = [], 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 EntityQueryResults() {Results = [], Success = false, Message = "Unable to retrieve the searchdomain - it likely exists, but some other error happened." });
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity? entity_ = SearchdomainHelper.CacheGetEntity(searchdomain_.entityCache, entityName);
|
Entity? entity_ = SearchdomainHelper.CacheGetEntity(searchdomain_.entityCache, entityName);
|
||||||
if (entity_ is null)
|
if (entity_ is null)
|
||||||
|
|||||||
@@ -87,9 +87,8 @@ public class SearchdomainController : ControllerBase
|
|||||||
[HttpGet("Update")]
|
[HttpGet("Update")]
|
||||||
public ActionResult<SearchdomainUpdateResults> Update(string searchdomain, string newName, string settings = "{}")
|
public ActionResult<SearchdomainUpdateResults> Update(string searchdomain, string newName, string settings = "{}")
|
||||||
{
|
{
|
||||||
try
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
{
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
Searchdomain searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
Dictionary<string, dynamic> parameters = new()
|
Dictionary<string, dynamic> parameters = new()
|
||||||
{
|
{
|
||||||
{"name", newName},
|
{"name", newName},
|
||||||
@@ -97,24 +96,29 @@ public class SearchdomainController : ControllerBase
|
|||||||
{"id", searchdomain_.id}
|
{"id", searchdomain_.id}
|
||||||
};
|
};
|
||||||
searchdomain_.helper.ExecuteSQLNonQuery("UPDATE searchdomain set name = @name, settings = @settings WHERE id = @id", parameters);
|
searchdomain_.helper.ExecuteSQLNonQuery("UPDATE searchdomain set name = @name, settings = @settings WHERE id = @id", parameters);
|
||||||
} catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to update searchdomain {searchdomain} - not found", [searchdomain]);
|
|
||||||
return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update searchdomain {searchdomain} - not found" });
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to update searchdomain {searchdomain} - Exception: {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]);
|
|
||||||
return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update searchdomain {searchdomain}" });
|
|
||||||
}
|
|
||||||
return Ok(new SearchdomainUpdateResults(){Success = true});
|
return Ok(new SearchdomainUpdateResults(){Success = true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("Query")]
|
||||||
|
public ActionResult<EntityQueryResults> Query(string searchdomain, string query, int? topN, bool returnAttributes = false)
|
||||||
|
{
|
||||||
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
|
List<(float, string)> results = searchdomain_.Search(query, topN);
|
||||||
|
List<EntityQueryResult> queryResults = [.. results.Select(r => new EntityQueryResult
|
||||||
|
{
|
||||||
|
Name = r.Item2,
|
||||||
|
Value = r.Item1,
|
||||||
|
Attributes = returnAttributes ? (searchdomain_.entityCache.FirstOrDefault(x => x.name == r.Item2)?.attributes ?? null) : null
|
||||||
|
})];
|
||||||
|
return Ok(new EntityQueryResults(){Results = queryResults, Success = true });
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost("UpdateSettings")]
|
[HttpPost("UpdateSettings")]
|
||||||
public ActionResult<SearchdomainUpdateResults> UpdateSettings(string searchdomain, [FromBody] SearchdomainSettings request)
|
public ActionResult<SearchdomainUpdateResults> UpdateSettings(string searchdomain, [FromBody] SearchdomainSettings request)
|
||||||
{
|
{
|
||||||
try
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
{
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
Searchdomain searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
Dictionary<string, dynamic> parameters = new()
|
Dictionary<string, dynamic> parameters = new()
|
||||||
{
|
{
|
||||||
{"settings", JsonSerializer.Serialize(request)},
|
{"settings", JsonSerializer.Serialize(request)},
|
||||||
@@ -122,36 +126,14 @@ public class SearchdomainController : ControllerBase
|
|||||||
};
|
};
|
||||||
searchdomain_.helper.ExecuteSQLNonQuery("UPDATE searchdomain set settings = @settings WHERE id = @id", parameters);
|
searchdomain_.helper.ExecuteSQLNonQuery("UPDATE searchdomain set settings = @settings WHERE id = @id", parameters);
|
||||||
searchdomain_.settings = request;
|
searchdomain_.settings = request;
|
||||||
} catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to update settings for searchdomain {searchdomain} - not found", [searchdomain]);
|
|
||||||
return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update settings for searchdomain {searchdomain} - not found" });
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to update settings for searchdomain {searchdomain} - Exception: {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]);
|
|
||||||
return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update settings for searchdomain {searchdomain}" });
|
|
||||||
}
|
|
||||||
return Ok(new SearchdomainUpdateResults(){Success = true});
|
return Ok(new SearchdomainUpdateResults(){Success = true});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("GetSearches")]
|
[HttpGet("GetSearches")]
|
||||||
public ActionResult<SearchdomainSearchesResults> GetSearches(string searchdomain)
|
public ActionResult<SearchdomainSearchesResults> GetSearches(string searchdomain)
|
||||||
{
|
{
|
||||||
Searchdomain searchdomain_;
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
try
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
{
|
|
||||||
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;
|
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
|
||||||
|
|
||||||
return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true });
|
return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true });
|
||||||
@@ -160,21 +142,8 @@ public class SearchdomainController : ControllerBase
|
|||||||
[HttpDelete("Searches")]
|
[HttpDelete("Searches")]
|
||||||
public ActionResult<SearchdomainDeleteSearchResult> DeleteSearch(string searchdomain, string query)
|
public ActionResult<SearchdomainDeleteSearchResult> DeleteSearch(string searchdomain, string query)
|
||||||
{
|
{
|
||||||
Searchdomain searchdomain_;
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
try
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
{
|
|
||||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
}
|
|
||||||
catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
|
||||||
return Ok(new SearchdomainDeleteSearchResult() { 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 SearchdomainDeleteSearchResult() { Success = false, Message = ex.Message });
|
|
||||||
}
|
|
||||||
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
|
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
|
||||||
bool containsKey = searchCache.ContainsKey(query);
|
bool containsKey = searchCache.ContainsKey(query);
|
||||||
if (containsKey)
|
if (containsKey)
|
||||||
@@ -188,21 +157,8 @@ public class SearchdomainController : ControllerBase
|
|||||||
[HttpPatch("Searches")]
|
[HttpPatch("Searches")]
|
||||||
public ActionResult<SearchdomainUpdateSearchResult> UpdateSearch(string searchdomain, string query, [FromBody]List<ResultItem> results)
|
public ActionResult<SearchdomainUpdateSearchResult> UpdateSearch(string searchdomain, string query, [FromBody]List<ResultItem> results)
|
||||||
{
|
{
|
||||||
Searchdomain searchdomain_;
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
try
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
{
|
|
||||||
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;
|
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
|
||||||
bool containsKey = searchCache.ContainsKey(query);
|
bool containsKey = searchCache.ContainsKey(query);
|
||||||
if (containsKey)
|
if (containsKey)
|
||||||
@@ -218,21 +174,8 @@ public class SearchdomainController : ControllerBase
|
|||||||
[HttpGet("GetSettings")]
|
[HttpGet("GetSettings")]
|
||||||
public ActionResult<SearchdomainSettingsResults> GetSettings(string searchdomain)
|
public ActionResult<SearchdomainSettingsResults> GetSettings(string searchdomain)
|
||||||
{
|
{
|
||||||
Searchdomain searchdomain_;
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
try
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
{
|
|
||||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
}
|
|
||||||
catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
|
||||||
return Ok(new SearchdomainSettingsResults() { Settings = null, 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 SearchdomainSettingsResults() { Settings = null, Success = false, Message = ex.Message });
|
|
||||||
}
|
|
||||||
SearchdomainSettings settings = searchdomain_.settings;
|
SearchdomainSettings settings = searchdomain_.settings;
|
||||||
return Ok(new SearchdomainSettingsResults() { Settings = settings, Success = true });
|
return Ok(new SearchdomainSettingsResults() { Settings = settings, Success = true });
|
||||||
}
|
}
|
||||||
@@ -240,21 +183,8 @@ public class SearchdomainController : ControllerBase
|
|||||||
[HttpGet("GetSearchCacheSize")]
|
[HttpGet("GetSearchCacheSize")]
|
||||||
public ActionResult<SearchdomainSearchCacheSizeResults> GetSearchCacheSize(string searchdomain)
|
public ActionResult<SearchdomainSearchCacheSizeResults> GetSearchCacheSize(string searchdomain)
|
||||||
{
|
{
|
||||||
Searchdomain searchdomain_;
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
try
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
{
|
|
||||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
}
|
|
||||||
catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
|
||||||
return Ok(new SearchdomainSearchCacheSizeResults() { SearchCacheSizeBytes = null, 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 SearchdomainSearchCacheSizeResults() { SearchCacheSizeBytes = null, Success = false, Message = ex.Message });
|
|
||||||
}
|
|
||||||
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
|
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
|
||||||
long sizeInBytes = 0;
|
long sizeInBytes = 0;
|
||||||
foreach (var entry in searchCache)
|
foreach (var entry in searchCache)
|
||||||
@@ -269,40 +199,17 @@ public class SearchdomainController : ControllerBase
|
|||||||
[HttpGet("ClearSearchCache")]
|
[HttpGet("ClearSearchCache")]
|
||||||
public ActionResult<SearchdomainInvalidateCacheResults> InvalidateSearchCache(string searchdomain)
|
public ActionResult<SearchdomainInvalidateCacheResults> InvalidateSearchCache(string searchdomain)
|
||||||
{
|
{
|
||||||
try
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
{
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
Searchdomain searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
searchdomain_.InvalidateSearchCache();
|
searchdomain_.InvalidateSearchCache();
|
||||||
} catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to invalidate search cache for searchdomain {searchdomain} - not found", [searchdomain]);
|
|
||||||
return Ok(new SearchdomainInvalidateCacheResults() { Success = false, Message = $"Unable to invalidate search cache for searchdomain {searchdomain} - not found" });
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to invalidate search cache for searchdomain {searchdomain} - Exception: {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]);
|
|
||||||
return Ok(new SearchdomainInvalidateCacheResults() { Success = false, Message = $"Unable to invalidate search cache for searchdomain {searchdomain}" });
|
|
||||||
}
|
|
||||||
return Ok(new SearchdomainInvalidateCacheResults(){Success = true});
|
return Ok(new SearchdomainInvalidateCacheResults(){Success = true});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("GetDatabaseSize")]
|
[HttpGet("GetDatabaseSize")]
|
||||||
public ActionResult<SearchdomainGetDatabaseSizeResult> GetDatabaseSize(string searchdomain)
|
public ActionResult<SearchdomainGetDatabaseSizeResult> GetDatabaseSize(string searchdomain)
|
||||||
{
|
{
|
||||||
Searchdomain searchdomain_;
|
(Searchdomain? searchdomain_, int? httpStatusCode, string? message) = SearchdomainHelper.TryGetSearchdomain(_domainManager, searchdomain, _logger);
|
||||||
try
|
if (searchdomain_ is null || httpStatusCode is not null) return StatusCode(httpStatusCode ?? 500, new SearchdomainUpdateResults(){Success = false, Message = message});
|
||||||
{
|
|
||||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
|
||||||
}
|
|
||||||
catch (SearchdomainNotFoundException)
|
|
||||||
{
|
|
||||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
|
||||||
return Ok(new SearchdomainGetDatabaseSizeResult() { SearchdomainDatabaseSizeBytes = null, 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 SearchdomainGetDatabaseSizeResult() { SearchdomainDatabaseSizeBytes = null, Success = false, Message = ex.Message });
|
|
||||||
}
|
|
||||||
long sizeInBytes = DatabaseHelper.GetSearchdomainDatabaseSize(searchdomain_.helper, searchdomain);
|
long sizeInBytes = DatabaseHelper.GetSearchdomainDatabaseSize(searchdomain_.helper, searchdomain);
|
||||||
return Ok(new SearchdomainGetDatabaseSizeResult() { SearchdomainDatabaseSizeBytes = sizeInBytes, Success = true });
|
return Ok(new SearchdomainGetDatabaseSizeResult() { SearchdomainDatabaseSizeBytes = sizeInBytes, Success = true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,4 +269,21 @@ public class SearchdomainHelper(ILogger<SearchdomainHelper> logger, DatabaseHelp
|
|||||||
var similarityMethod = new SimilarityMethod(jsonDatapoint.SimilarityMethod, logger) ?? throw new SimilarityMethodNotFoundException(jsonDatapoint.SimilarityMethod);
|
var similarityMethod = new SimilarityMethod(jsonDatapoint.SimilarityMethod, logger) ?? throw new SimilarityMethodNotFoundException(jsonDatapoint.SimilarityMethod);
|
||||||
return new Datapoint(jsonDatapoint.Name, probMethod_embedding, similarityMethod, hash, [.. embeddings.Select(kv => (kv.Key, kv.Value))]);
|
return new Datapoint(jsonDatapoint.Name, probMethod_embedding, similarityMethod, hash, [.. embeddings.Select(kv => (kv.Key, kv.Value))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static (Searchdomain?, int?, string?) TryGetSearchdomain(SearchdomainManager searchdomainManager, string searchdomain, ILogger logger)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Searchdomain searchdomain_ = searchdomainManager.GetSearchdomain(searchdomain);
|
||||||
|
return (searchdomain_, null, null);
|
||||||
|
} catch (SearchdomainNotFoundException)
|
||||||
|
{
|
||||||
|
logger.LogError("Unable to update searchdomain {searchdomain} - not found", [searchdomain]);
|
||||||
|
return (null, 500, $"Unable to update searchdomain {searchdomain} - not found");
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError("Unable to update searchdomain {searchdomain} - Exception: {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]);
|
||||||
|
return (null, 404, $"Unable to update searchdomain {searchdomain}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
12
src/Shared/Models/BaseModels.cs
Normal file
12
src/Shared/Models/BaseModels.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Shared.Models;
|
||||||
|
|
||||||
|
public class SuccesMessageBaseModel
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Success")]
|
||||||
|
public required bool Success { get; set; }
|
||||||
|
[JsonPropertyName("Message")]
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
public string? Message { get; set; }
|
||||||
|
}
|
||||||
@@ -3,14 +3,10 @@ using System.Text.Json.Serialization;
|
|||||||
namespace Shared.Models;
|
namespace Shared.Models;
|
||||||
|
|
||||||
|
|
||||||
public class EntityQueryResults
|
public class EntityQueryResults : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Results")]
|
[JsonPropertyName("Results")]
|
||||||
public required List<EntityQueryResult> Results { get; set; }
|
public required List<EntityQueryResult> Results { get; set; }
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EntityQueryResult
|
public class EntityQueryResult
|
||||||
@@ -24,18 +20,14 @@ public class EntityQueryResult
|
|||||||
public Dictionary<string, string>? Attributes { get; set; }
|
public Dictionary<string, string>? Attributes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EntityIndexResult
|
public class EntityIndexResult : SuccesMessageBaseModel {}
|
||||||
{
|
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class EntityListResults
|
public class EntityListResults
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Results")]
|
[JsonPropertyName("Results")]
|
||||||
public required List<EntityListResult> Results { get; set; }
|
public required List<EntityListResult> Results { get; set; }
|
||||||
|
[JsonPropertyName("Message")]
|
||||||
|
public string? Message { get; set; }
|
||||||
[JsonPropertyName("Success")]
|
[JsonPropertyName("Success")]
|
||||||
public required bool Success { get; set; }
|
public required bool Success { get; set; }
|
||||||
}
|
}
|
||||||
@@ -80,11 +72,5 @@ public class EmbeddingResult
|
|||||||
public required float[] Embeddings { get; set; }
|
public required float[] Embeddings { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EntityDeleteResults
|
public class EntityDeleteResults : SuccesMessageBaseModel {}
|
||||||
{
|
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,109 +11,46 @@ public class SearchdomainListResults
|
|||||||
public string? Message { get; set; }
|
public string? Message { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SearchdomainCreateResults
|
public class SearchdomainCreateResults : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Id")]
|
[JsonPropertyName("Id")]
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SearchdomainUpdateResults
|
public class SearchdomainUpdateResults : SuccesMessageBaseModel {}
|
||||||
|
|
||||||
|
public class SearchdomainDeleteResults : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SearchdomainDeleteResults
|
|
||||||
{
|
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("DeletedEntities")]
|
[JsonPropertyName("DeletedEntities")]
|
||||||
public required int DeletedEntities { get; set; }
|
public required int DeletedEntities { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SearchdomainSearchesResults
|
public class SearchdomainSearchesResults : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
[JsonPropertyName("Searches")]
|
[JsonPropertyName("Searches")]
|
||||||
public required Dictionary<string, DateTimedSearchResult> Searches { get; set; }
|
public required Dictionary<string, DateTimedSearchResult> Searches { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SearchdomainDeleteSearchResult
|
public class SearchdomainDeleteSearchResult : SuccesMessageBaseModel {}
|
||||||
|
|
||||||
|
public class SearchdomainUpdateSearchResult : SuccesMessageBaseModel {}
|
||||||
|
|
||||||
|
public class SearchdomainSettingsResults : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
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
|
|
||||||
{
|
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Settings")]
|
[JsonPropertyName("Settings")]
|
||||||
public required SearchdomainSettings? Settings { get; set; }
|
public required SearchdomainSettings? Settings { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SearchdomainSearchCacheSizeResults
|
public class SearchdomainSearchCacheSizeResults : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("SearchCacheSizeBytes")]
|
[JsonPropertyName("SearchCacheSizeBytes")]
|
||||||
public required long? SearchCacheSizeBytes { get; set; }
|
public required long? SearchCacheSizeBytes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SearchdomainInvalidateCacheResults
|
public class SearchdomainInvalidateCacheResults : SuccesMessageBaseModel {}
|
||||||
|
|
||||||
|
public class SearchdomainGetDatabaseSizeResult : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SearchdomainGetDatabaseSizeResult
|
|
||||||
{
|
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("SearchdomainDatabaseSizeBytes")]
|
[JsonPropertyName("SearchdomainDatabaseSizeBytes")]
|
||||||
public required long? SearchdomainDatabaseSizeBytes { get; set; }
|
public required long? SearchdomainDatabaseSizeBytes { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,8 @@ using System.Text.Json.Serialization;
|
|||||||
|
|
||||||
namespace Shared.Models;
|
namespace Shared.Models;
|
||||||
|
|
||||||
public class ServerGetModelsResult
|
public class ServerGetModelsResult : SuccesMessageBaseModel
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
|
||||||
public required bool Success { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Message")]
|
|
||||||
public string? Message { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Models")]
|
[JsonPropertyName("Models")]
|
||||||
public string[]? Models { get; set; }
|
public string[]? Models { get; set; }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user